protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["ID"] == null)
return;
string AttaID = Request.QueryString["ID"].ToString();
string FileName = Request.QueryString["FileName"].ToString();
byte[] filebyte = new WebClass.Errands().Customer_Atta_Get(AttaID);
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment;filename=" +Server.UrlEncode(FileName));
Response.AppendHeader("Content-Length", filebyte.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.OutputStream.Write(filebyte, 0, filebyte.Length);
Response.End();
}
本文展示了一个ASP.NET中实现文件下载的例子。通过检查请求参数并从数据库获取文件内容,此方法设置了适当的HTTP响应头来触发浏览器下载指定文件。
1820

被折叠的 条评论
为什么被折叠?



