zoukankan      html  css  js  c++  java
  • ASP.NET MVC 返回文件

    将文件写入Response

            public ActionResult Zip()
            {
                string fname = Server.MapPath("~\App_Data\TestDB.zip");
    
                FileStream fs=new FileStream(fname,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
    
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
    
                Response.ContentType = "application/vnd.android.package-archive";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + "MyApp.apk");
    
    
    
    
                Response.AppendHeader("Content-Length", "" + fs.Length);
               
                byte[] bts=new byte[fs.Length];
                fs.Read(bts, 0,(int) fs.Length);
                Response.BinaryWrite(bts);
                return null;
            }
    Write File Bytes to Response
            public ActionResult Zip()
            {
                string fname = Server.MapPath("~\App_Data\bb.zip");
    
                FileStream fs = new FileStream(fname, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
    
                Response.ContentType = "application/vnd.android.package-archive";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + "MyAppb.apk");
    
                Response.AppendHeader("Content-Length", "" + fs.Length);
    
    
    
    
                byte[] bts = new byte[fs.Length];
                fs.Read(bts, 0, (int)fs.Length);
    
                Response.OutputStream.Write(bts,0,bts.Length);
                return null;
            }
  • 相关阅读:
    洛谷 题解 P5595 【【XR-4】歌唱比赛】
    洛谷 题解 CF1151D 【Stas and the Queue at the Buffet】
    洛谷 题解 CF299A 【Ksusha and Array】
    仙人掌找环
    2-SAT
    带花树
    帮我背单词
    csp2019退役祭
    P5284 [十二省联考2019]字符串问题 题解
    【网络流24题】魔术球问题
  • 原文地址:https://www.cnblogs.com/netact/p/3788964.html
Copyright © 2011-2022 走看看