如何制作可下载的内容
问题描述:
我将图像存储在数据库中作为字节数组。我想在点击按钮后在页面中打开图像。我已经尝试了response.binarywrite()方法,保持页面内容类型=图像但不能保存在jpg中或jpeg format.so如何在c#?
I store images in database as byte array.I want to open the image in a page after clicking button.I have tried response.binarywrite() method keeping the page content type="image" but can not save that in jpg or jpeg format.so how to do in c#?
答
在下载图片页面中使用以下代码:
Use the below code in the download picture page:
string strFileName ="pic.jpg";
byte[] bytes = // get byes from the database table using your DB code/function
Response.Clear();
Response.AppendHeader("Content-Disposition", "filename=" + strFileName);
Response.AppendHeader("Content-Length", bytes.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytes);
Response.End();