• 文件下载


     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){ //存在文件
    if(upload.PostedFile.ContentLength< 100000){ //判断文件大小
    string fullName =upload.PostedFile.FileName; //获取文件全称
    string fileName =fullName.Substring(fullName.LastIndexOf("\")+1); //获取文件全称
    string serverpath=Server.MapPath("~//File//")+fileName; //存放到服务器路径
    upload.PostedFile.SaveAs(serverpath);
    }
    }

    }
  • 相关阅读:
    Python Install for windows X64
    CentOS 7 Install Gitlab CE
    centos 7安装vmtools时提示The path "" is not a valid path to the xxx kernel headers.
    Jenkins install
    gradle 编译 No such property: sonatypeUsername错误解决
    Hololens 开发环境配置(转)
    Krapo 2
    Krapno 1
    dubbo 常见错误
    groupby
  • 原文地址:https://www.cnblogs.com/Evaniko/p/5116269.html
Copyright © 2020-2023  润新知