亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#文件上傳與下載的實(shí)現(xiàn)方法

 更新時(shí)間:2017年08月29日 10:58:59   作者:小倔驢  
這篇文章主要為大家詳細(xì)介紹了C#文件上傳與下載的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C#實(shí)現(xiàn)文件上傳與下載的具體代碼,供大家參考,具體內(nèi)容如下

C#實(shí)現(xiàn)文件上傳代碼:

 public ActionResult Upload()
    {
      // var pathUrl = "http://" + Request.Url.Authority;
      var file = Request.Files["Filedata"];

      var uploadFileName = file.FileName;

      string filePath = "/File/" + uploadFileName;
      string AbsolutePath = Server.MapPath(filePath);
      file.SaveAs(AbsolutePath);       //將上傳的東西保存     
      return Json(new { FileName = uploadFileName, FilePath = filePath });

    }

C#實(shí)現(xiàn)文件下載功能:

 public ActionResult DownLoad(string FileName)
    {
      string fileName = FileName;//客戶端保存的文件名 
      string filePath = Server.MapPath("/File/"+ FileName);//路徑    
                                 //以字符流的形式下載文件   
      FileStream fs = new FileStream(filePath, FileMode.Open);
      byte[] bytes = new byte[(int)fs.Length];
      fs.Read(bytes, 0, bytes.Length);
      fs.Close();
      Response.ContentType = "application/octet-stream";

      //通知瀏覽器下載文件而不是打開  
      Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
      Response.BinaryWrite(bytes);
      Response.Flush();
      Response.End();
      return Json("");
    }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論