将文件写入Response
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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; }
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; }