Open file from server and send to browser

In my asp.net application, I create a pdf file and save it in the App_Data folder on the server. Then I want to open this file that the user can print.

How do I open this file in a browser? Send in http header etc.? Does anyone have examples?

Please, help;)

+2


a source to share


2 answers


you can save the file to a folder and then give the user a page where they can click the link to download the file. just remember to create a unique name for the file (using guid), otherwise users will download each other.

you can also return the file in response. the following code is for returning an excel file, but it can be easily modified for pdf.



Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName)); 
Response.TransmitFile(Server.MapPath(string.Format("{0}/{1}", BasePath, fileName))); 

      

+3


a source


You can simply redirect the user to it with Response.Redirect()

. The user can then decide if he wants to print it.



0


a source







All Articles