[C#] syntaxhighlighter_viewsource syntaxhighlighter_copycode 方法1:WebClient 读取文件流下载
WebClient client = new WebClient();
byte[] bytes = client.DownloadData(Url);
HttpContext.Response.ContentType = "application/octet-stream";
HttpContext.Response.AddHeader("Content-Disposition", "attachement;filename=" + HttpUtility.UrlEncode(Path.GetFileName(Url)));
HttpContext.Response.AddHeader("Content-Length", bytes.Length.ToString());
HttpContext.Response.OutputStream.Write(bytes, 0, bytes.Length);
HttpContext.Response.Flush();
HttpContext.Response.Clear();
方法2:WebClient 直接下载到指定文件夹
WebClient client = new WebClient();
client.DownloadFile(Url, @"D:\"+HttpUtility.UrlEncode(Path.GetFileName(Url)));
|