首页 > 其他 > 详细

文件下载

时间:2016-01-09 15:09:43      阅读:240      评论:0      收藏:0      [点我收藏+]
 1  
 2     
//下载文件 3 public void DownLoad(string url){ 4 url=ConvertServerPath(url); 6 string filePath =Server.MapPath(url); 7 FileInfo fileinfo =new FileInfo (); 8 Response.Clear(); 9 Response.ClearContent(); 10 Response.ClearHeaders(); 11 Response.AddHeader("Content-Disposition","attachment;filename"+fileInfo.Name); 12 Response.AddHeader("Content-Length", fileInfo.Length.ToString()); 13 Response.AddHeader("Content-Transfer-Encoding", "binary"); 14 Response.ContentType = "application/octet-stream"; 15 Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); 16 Response.WriteFile(fileinfo.FullName); 17 Response.Flush(); 18 Response.End(); 19 20 } 21 22 23 //转换成网站路径 24 public string ConvertServerPath(string url){ 25 string mapPath =HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath.ToString()); //系统根路径 28 string xdPath=url.Replace(mapPath,"~"); //网站路径 30 xdPath=xdpath.Replace(@"\",@"/"); 31 return xdPath; 3 }

 

 

 
//上传文件

public void UpLoad(FileUpload upload){
if(upload.HasFile){ //存在文件
string file
}

}

 

文件下载

原文:http://www.cnblogs.com/Evaniko/p/5116269.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!