C#下载Url文件到本地
protected void Page_Load(object sender, EventArgs e)
{
string filePath = Request.Params["FilePath"];
string fileName = HttpUtility.UrlDecode(Request.Params["FileName"]);
if (filePath != null)
{
DownLoad(fileName, filePath);
}
}
public void DownLoad(string FileName, string FilePath)
{
string result = string.Empty;
WebClient wc = new WebClient();
wc.BaseAddress = FilePath;
byte[] bytes;
bytes = wc.DownloadData(wc.BaseAddress);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", HttpUtility.UrlEncode(
FileName), System.Text.Encoding.UTF8));
MemoryStream ms = new MemoryStream(bytes); ms.WriteTo(Response.OutputStream); ms.Dispose(); ms.Close();
}
最新文章
- cas与NGINX整合(转)
- [MetaHook] Load DTX texture to OpenGL
- 用 BPL 封装数据连接
- ios专题 - 单例模式的实现
- <;转载>;构造函数与拷贝构造函数
- ASP.NET MVC 学习之路-3
- nopCommerce 3.9 大波浪系列 之 global.asax
- Lucene详解
- spring不走注解的原因
- angular-material(一)
- 图片上传预览js
- JS 字符ASCII转换
- RHEL6.2 ORACLE11G
- Odoo9.0模块开发全流程
- c++ const enum #define
- Fully qualified name FQCN
- 11.22Daily Scrum
- devm_xxx机制
- BMP文件组成
- HDU 1280 前m大的数(排序,字符串)