ASP.NET檔案下載的實用方法

iDotNetSpace發表於2010-05-31

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部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-664097/,如需轉載,請註明出處,否則將追究法律責任。

相關文章