ASP.net资源下载
2013-03-15 17:31
239 查看
protected void downF()
{
//判断是否选择文件名
//获取文件路径
//string path = Server.MapPath("File/") + Session["file"].ToString();//要下载的资源在本地
string path = @"\\192.168.1.90\wwwroot\img.cn-school.com\images\667027ee9425480e8881fd923158317d.png";//要下载的资源在某个服务器
//初始化 FileInfo 类的实例,它作为文件路径的包装
FileInfo fi = new FileInfo(path);
// FileInfo f2 = new FileInfo(path1);
//判断文件是否存在
if (fi.Exists)
{
//将文件保存到本机上
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fi.Name));
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(fi.FullName);
Response.End();
}
else
{
Page.RegisterStartupScript("", "<script>alert('请先选择文件名!')</script>");//5~1-a-s-p-x
}
{
//判断是否选择文件名
//获取文件路径
//string path = Server.MapPath("File/") + Session["file"].ToString();//要下载的资源在本地
string path = @"\\192.168.1.90\wwwroot\img.cn-school.com\images\667027ee9425480e8881fd923158317d.png";//要下载的资源在某个服务器
//初始化 FileInfo 类的实例,它作为文件路径的包装
FileInfo fi = new FileInfo(path);
// FileInfo f2 = new FileInfo(path1);
//判断文件是否存在
if (fi.Exists)
{
//将文件保存到本机上
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fi.Name));
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(fi.FullName);
Response.End();
}
else
{
Page.RegisterStartupScript("", "<script>alert('请先选择文件名!')</script>");//5~1-a-s-p-x
}
相关文章推荐
- 收藏:ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小) (转自: Arhrun)
- 最受欢迎的ASP.NET的CMS下载(资源共享)
- ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小)
- ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小)
- 收藏:ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小) (转自: Arhrun)
- ASP.NET中文件上传下载方法集合(上传限制,保存方式-二进制或文件形式,上传Internet上的资源 )
- 优化asp.net ajax的脚本资源下载
- 收藏:ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小)
- ASP.NET 如何有效的防止资源被盗(防盗链下载)
- ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小)
- ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小)
- ASP.NET中文件上传下载方法集合(上传限制,保存方式-二进制或文件形式,上传Internet上的资源 )
- ASP.NET中文件上传下载方法集合(上传限制,保存方式-二进制或文件形式,上传Internet上的资源 )
- ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小)
- (摘录)ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小)
- ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小)
- ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小)
- ASP.NET提供文件下载函数(支持大文件、续传、速度限制、资源占用小)
- 《ASP.NET 2.0 揭密》资源下载地址 和《道不远人》资源下载地址
- ASP.NET 视频学习资源(下载地址)