点击下载功能
点击,转到一般处理程序,在一般处理程序中将数据库中二进制流转换后,实现下载
public void ProcessRequest(HttpContext context)
{
Guid FileID = Guid.Parse(context.Request.Params["fileid"].ToString());
XML_SYS_FILEEntity file = new XML_SYS_FILEEntity() { XFL_ID = FileID };
if (file.RemotingInitEntity<SYSTEMLink>())
{
string FileName = System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(file.XFL_FILE_NAMEDisplayValue + file.XFL_FILE_EXTEND_NAMEDisplayValue));
string leng = file.XFL_FILE_LENGTHDisplayValue;
context.Response.Clear();
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("Content-Disposition", "attachement;filename=" + file.XFL_FILE_NAMEDisplayValue);
context.Response.AddHeader("Content-Length", leng.ToString());
context.Response.BinaryWrite(file.XFL_FILE_BYTES);
context.Response.End();
}
}
public bool IsReusable
{
get
{
return false;
}
}
但是点击后便直接打开了文件
[解决办法]
Response.Clear();
Response.ClearHeaders();
Response.Buffer = true;
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fi.Name));
Response.WriteFile(fi.FullName);
Response.End();
Response.Flush();
Response.Clear();
[解决办法]