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;
            }
  • 相关阅读:
    linux Crontab 使用
    彻底搞懂 call() 和 apply() 方法
    (day10) 28. 实现strStr()
    (day9)357. 计算各个位数不同的数字个数
    (day7) 168. Excel表列名称
    (day6) 319. 灯泡开关
    (day5)350 两个数组的交集 II
    (day4)581.最短无序连续子数组
    day3 字符串的排列
    JS类型转换
  • 原文地址:https://www.cnblogs.com/netact/p/3788964.html
Copyright © 2011-2022 走看看