[英]Download files in C#
我正在嘗試使用C#下載文件(包括pdf,zip,圖像等)。 我已經嘗試了以下鏈接中的代碼。
http://www.daniweb.com/web-development/aspnet/threads/252778
http://dotnetslackers.com/Community/blogs/haissam/archive/2007/04/03/Downloading-Files-C_2300_.aspx
它在IE中按預期工作。 但是在Firefox中,下載的zip和圖像文件已損壞。
問題可能出在Content-Disposition標頭中的FILENAME參數上。
您可以按照以下規則嘗試示例代碼:
Content-Type標頭應引用未知的MIME類型
FileInfo fi = new FileInfo(@"c:\\picture.bmp"); Response.Clear(); Response.ContentType = "application/x-unknown"; Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", System.Web.HttpUtility.UrlPathEncode(fi.Name))); Response.AddHeader("Content-Length", fi.Length.ToString()); Response.TransmitFile(fi.FullName); Response.End();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.