zoukankan      html  css  js  c++  java
  • 文件下载

     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);
    }
    }

    }
  • 相关阅读:
    go 学习笔记---chan
    golang学习笔记---Goroutine
    golang ---Learn Concurrency
    golang ----并发 && 并行
    golang 学习笔记 使用cmd
    并发程序与并行程序
    golang学习笔记 ---interface
    golang --- map如何判断key是否存在
    golang学习 ---defer语句
    golang --for语句
  • 原文地址:https://www.cnblogs.com/Evaniko/p/5116269.html
Copyright © 2011-2022 走看看