将文件写入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

相关文章: