使用NET如何實現文件下載(以流的形式輸出下載)
要實現這種下載方式,形式為,直接彈出保存對話框,讓客戶端選擇保存並下載!
前提是:先引入命名空間:
using System.IO;
以下就是實現過程,敬請查看!
FileInfo DownloadFile = new FileInfo(“這裡填寫閣下的文件路徑,填寫個完整的路徑,否則就完完了”);
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();
才疏技短,見笑見笑!