I have a aspx page which returns a pdf file with this code:
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "application/pdf"
HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename=Order-" & Request("OrderNo") & ".pdf")
HttpContext.Current.Response.BinaryWrite(pdfContent)
HttpContext.Current.Response.End()
What modifications needs to be done to the code so the file is saved to the hard drive on the server? I guess BinaryWrite has to be replaced with something else, but what?
I’m very grateful for help!
Just specify the Path and the pdfcontent as parameters to the
File.WriteAllBytesmethod as so:You generally can’t save any content outside your local application directory unless you configure the Application pool your application runs under with a user that has enough privileges to write to the destination directory. But out of the box, you should be able to write to subdirectories inside your web application.