Reading a binary file and using Response.BinaryWrite()

后端 未结 10 1927
既然无缘
既然无缘 2020-11-28 12:16

I have an app that needs to read a PDF file from the file system and then write it out to the user. The PDF is 183KB and seems to work perfectly. When I use the code at th

10条回答
  •  独厮守ぢ
    2020-11-28 12:42

    We've used this with a lot of success. WriteFile do to the download for you and a Flush / End at the end to send it all to the client.

                //Use these headers to display a saves as / download
                //Response.ContentType = "application/octet-stream";
                //Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}.pdf", Path.GetFileName(Path)));
    
                Response.ContentType = "application/pdf";
                Response.AddHeader("Content-Disposition", String.Format("inline; filename={0}.pdf", Path.GetFileName(Path)));
    
                Response.WriteFile(path);
                Response.Flush();
                Response.End();
    

提交回复
热议问题