我正在使用ASP.NET和C#。在ASP.NET中检索上传的文件
我已经做了一个文件上传页面,其中使用可以上传他们的文件。我保存在数据库中的三个字段,
- 文档名称[NVARCHAR]
- 文件[图片]
- DocumentType [NVARCHAR]
现在,我可以在添加记录数据库,成功。现在我想在gridview中显示它,例如DocumentName,DocumentType和下载文件的链接。
我试图通过检索记录并将它们分配给gridview,但我只得到两列。
我正在使用ASP.NET和C#。在ASP.NET中检索上传的文件
我已经做了一个文件上传页面,其中使用可以上传他们的文件。我保存在数据库中的三个字段,
现在,我可以在添加记录数据库,成功。现在我想在gridview中显示它,例如DocumentName,DocumentType和下载文件的链接。
我试图通过检索记录并将它们分配给gridview,但我只得到两列。
既然你是存储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();
}
我认为你需要手动创建下载文件的链接。我不认为'GridView'可以自动为你做这个。 – bzlm 2010-08-05 10:30:42
我创造了这个: asp:LinkButton> –
Rahul
2010-08-05 10:36:31
看起来不错。它工作吗? – bzlm 2010-08-05 10:49:04