[英]Retrieve uploaded file in ASP.NET
我正在使用ASP.NET和C#。
我做了一个文件上传页面,在其中可以使用其文件上传。 我在数据库中保存了三个字段,
现在,我能够成功地在数据库中添加记录。 现在,我想在gridview中显示它,例如DocumentName,DocumentType以及下载文件的链接。
我尝试通过检索记录并将它们分配给gridview来进行尝试,但是我仅得到两列。
您必须创建一个提供实际文件的下载处理程序。
处理程序可以从表中检索Binary并将其直接写入输出流。
然后,网格视图将指向此处理程序
由于将文件存储在DB中,因此必须编写代码以读取文件数据,添加适当的标头并执行response.write
例如
在您的LinkButton点击处理程序上,代码将类似于
private void lnkDownload_Click(object sender,args)
{
//if you are using dataset the data will be of type byte array byte[]
//assuming you have assign the binary data to byte array
byte[] data;
Response.Clear(); //clear buffer
Response.ContentType = "image/gif"; //should be the MIME type of the document see http://www.w3schools.com/media/media_mimeref.asp for the complete list
Response.AddHeader("content-disposition", "attachment;filename=" + yourfilename); //tell the browser the file is to be downloaded
Response.BinaryWrite(data);
Response.End();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.