读书人

文件下载,该如何处理

发布时间: 2012-03-12 12:45:33 作者: rapoo

文件下载
现在已知一个文件路径: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            { }        } 

读书人网 >asp.net

热点推荐