ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ASP.NET文件下载的实用方法

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

原创 Linux操作系统 作者:iDotNetSpace 时间:2010-05-31 15:57:10 0 删除 编辑

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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-664097/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    2376
  • 访问量
    5766144