现在已知一个文件路径:http://www.xxx.com/123.txt
怎么把这个文件下载到:~/file/123.txt
------解决方案--------------------------------------------------------
貌似根据浏览器的安全限制 只能通知浏览器弹出框`
------解决方案--------------------------------------------------------
弹出框自己选择地址不行么?
------解决方案--------------------------------------------------------
你这样不是把下载地址写死了,
每次都是这个路径...
难道这句话程序只用跑一次就行吗?
------解决方案--------------------------------------------------------
- C# code
public void DownFile(string url) { if (string.IsNullOrEmpty(url)) return; try { WebClient UrlFile = new WebClient(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.BufferOutput = false; HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8)); byte[] b = UrlFile.DownloadData(url); HttpContext.Current.Response.BinaryWrite(b); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } catch { } }