IT猫扑网文章教程

分类分类

ASP.NET文件下载的实用方法

2015-06-28 00:00作者:网管联盟

  下载方法

  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();

  }

  调用方法

  string path= Server.MapPath(&fujian/&+文件名称);//path为服务器存放文件的路径

  FileDownload(path);

展开全部

相关文章

说两句网友评论
    我要跟贴
    取消