您的位置:首页 > 编程语言 > ASP

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
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐