asp.net页面中文件下载的2种方式

//Write pdf bytes to outputstream
        // 在线打开
        if (DKFS == "pdf")
        {
            Response.ContentType = "application/pdf";
        }
        // 下载
        if (DKFS == "octet-stream")
        {
            Response.AddHeader("Content-Disposition", string.Format("attachment;Filename={0}.pdf", Server.UrlEncode(string.Format("租赁意见书({0})", CZRXM))));
        }

通常使用:Response.BinaryWrite(m.ToArray());//m是MemoryStream

记得最后加上

   Response.OutputStream.Flush();
        Response.OutputStream.Close();
        Response.End();// 很多文章都没有这一句,但是非常重要,我不加就会在post出来的文件末尾加上当前页面代码...好杯具

原文地址:https://www.cnblogs.com/keyrratuff/p/1633579.html