asp.net中用文件流方式下载文件,后台代码无错,前台浏览器没有下载反应? 20
stringfilename=context.Request["fileName"].ToString();stringfileName="【下载】"+filename;...
string filename = context.Request["fileName"].ToString();
string fileName = "【下载】" + filename;//客户端保存的文件名
string filePath = System.Web.HttpContext.Current.Request.MapPath("~/UpFile/TraceCode/" + filename + "");//路径
FileStream fileStream = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fileStream.Length];
fileStream.Read(bytes, 0, bytes.Length);
fileStream.Close();
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
System.Web.HttpContext.Current.Response.BinaryWrite(bytes);
System.Web.HttpContext.Current.Response.Flush();
//System.Web.HttpContext.Current.Response.End();
//System.Web.HttpContext.Current.Response.Close();
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest(); 展开
string fileName = "【下载】" + filename;//客户端保存的文件名
string filePath = System.Web.HttpContext.Current.Request.MapPath("~/UpFile/TraceCode/" + filename + "");//路径
FileStream fileStream = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fileStream.Length];
fileStream.Read(bytes, 0, bytes.Length);
fileStream.Close();
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
System.Web.HttpContext.Current.Response.BinaryWrite(bytes);
System.Web.HttpContext.Current.Response.Flush();
//System.Web.HttpContext.Current.Response.End();
//System.Web.HttpContext.Current.Response.Close();
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest(); 展开
1个回答
展开全部
string filename = context.Request["fileName"].ToString();
string fileName = "【下载】" + filename;//客户端保存的文件名
string filePath = System.Web.HttpContext.Current.Request.MapPath("~/UpFile/TraceCode/" + filename + "");//路径
FileStream fileStream = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fileStream.Length];
fileStream.Read(bytes, 0, bytes.Length);
fileStream.Close();
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
System.Web.HttpContext.Current.Response.BinaryWrite(bytes);
System.Web.HttpContext.Current.Response.Flush();
//System.Web.HttpContext.Current.Response.End();
//System.Web.HttpContext.Current.Response.Close();
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询