MIME让TXT可下载

网友投稿 631 2022-12-01

MIME让TXT可-

MIME让TXT可-

这是以前写论坛的-时用的代码

public void ProcessRequest(HttpContext context) { string name = "d:\\abc.txt"; //System.IO.FileInfo aFile = new System.IO.FileInfo(name); //string na = Path.GetFileName(name); //context.Response.Clear(); //context.Response.ClearHeaders(); //context.Response.BufferOutput = false; // context.Response.ContentType = "application/octet-stream"; context.Response.AppendHeader("Content-disposition", "attachment;filename=abc.txt"); // context.Response.AppendHeader("Content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(na, System.Text.Encoding.UTF8)); // context.Response.AddHeader("Content-Length",aFile.Length.ToString()); context.Response.WriteFile(name); //context.Response.Flush(); //context.Response.End(); } public bool IsReusable { get { return false; } } private void OutPutFile(string filePath) { FileStream fs = File.OpenRead(Server.MapPath(filePath)); BinaryReader br = new BinaryReader(fs); Byte[] fileData = new byte[fs.Length]; br.Read(fileData, 0, fileData.Length); Response.Clear(); Response.ClearHeaders(); Response.BufferOutput = false; Response.ContentType = "application/force-download"; Response.AddHeader("Content-Disposition:", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(filePath),System.Text.Encoding.UTF8)); Response.AddHeader("Content-Length", fileData.Length.ToString()); Response.BinaryWrite(fileData); Response.Flush(); br.Close(); fs.Close(); Response.End(); }

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:VerifyRenderingInServerForm和EnableEventValidation引发的两个问题
下一篇:Solaris 10 x86 上折腾Mono
相关文章

 发表评论

暂时没有评论,来抢沙发吧~