在asp.net中怎么下载txt类型的文件.我写的时候他在IE中打开了.并没有提示下载.

时间:2021-12-14 00:28:53
在asp.net中怎么下载txt类型的文件.我写的时候他在IE中打开了.并没有提示下载.

6 个解决方案

#1


直接写超连接就可下载!

#2


指定其Url就能下载...

#3


context.Response.ContentType = "text/plain";

#4


context.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);

#5


引用高手代码
private      void      FileDownload(string      FullFileName)        
      {        
      FileInfo      DownloadFile      =      new      FileInfo(FullFileName);            
      Response.Clear();        
      Response.ClearHeaders();        
      Response.Buffer=false;        
      Response.ContentType="application/octet-stream";        
      Response.AppendHeader("Content-Disposition","attachment;filename="      +HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));        
      Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());        
      Response.WriteFile(DownloadFile.FullName);        
      Response.Flush();        
      Response.End();        
      }        

#6


mark      你是唐松华吧      呵呵 

#1


直接写超连接就可下载!

#2


指定其Url就能下载...

#3


context.Response.ContentType = "text/plain";

#4


context.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);

#5


引用高手代码
private      void      FileDownload(string      FullFileName)        
      {        
      FileInfo      DownloadFile      =      new      FileInfo(FullFileName);            
      Response.Clear();        
      Response.ClearHeaders();        
      Response.Buffer=false;        
      Response.ContentType="application/octet-stream";        
      Response.AppendHeader("Content-Disposition","attachment;filename="      +HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));        
      Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());        
      Response.WriteFile(DownloadFile.FullName);        
      Response.Flush();        
      Response.End();        
      }        

#6


mark      你是唐松华吧      呵呵