WebClient 文件下载
生活随笔
收集整理的這篇文章主要介紹了
WebClient 文件下载
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
//文件地址var path = Utils.GetQueryStringValue("path");//帶有http//下載文件到前臺文件夾Music下WebClient client = new WebClient();string URLAddress = Common.Utils.GetDataCenterImgUrl()+path;string receivePath = HttpContext.Current.Server.MapPath("~/music/");string filepath = receivePath + System.IO.Path.GetFileName(URLAddress);client.DownloadFile(URLAddress, filepath);//下載文件HttpContext.Current.Response.ContentType = "application/ms-download";string s_path = filepath;System.IO.FileInfo file = new System.IO.FileInfo(s_path);HttpContext.Current.Response.Clear();HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");HttpContext.Current.Response.Charset = "utf-8";HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());HttpContext.Current.Response.WriteFile(file.FullName);HttpContext.Current.Response.Flush();HttpContext.Current.Response.Clear();HttpContext.Current.Response.End();
?
轉(zhuǎn)載于:https://www.cnblogs.com/hausthy/p/4441282.html
總結(jié)
以上是生活随笔為你收集整理的WebClient 文件下载的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html5 XMLHttpRequest
- 下一篇: JavaScript的变量作用域深入理解