netmajor
netmajor

Reputation: 6585

Open file from server and send to browser

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

How to open this file in browser ? Send it in http header etc ? Someone have some examples?

Please help ;)

Upvotes: 2

Views: 4659

Answers (2)

yamspog
yamspog

Reputation: 18333

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

you could also return the file in the response. the following code is for returning an excel file, but 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))); 

Upvotes: 3

Matthew Jones
Matthew Jones

Reputation: 26190

You could just redirect the user to it using Response.Redirect(). Then the user could decide if s/he wants to print it.

Upvotes: 0

Related Questions