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