Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi all,

In my project i need to open pdf files,if i add the pdf into my solution i am able to open but how to open pdf without adding to my solution, which is in local system.
Posted

If you have the PDF file on your local machine or stored on a server you can add the path to the button's click event or in the HyperLink's NavigateUrl. You can do something as simple as the following assuming you have acrobat installed:-
Response.Redirect("~/somePDFFile.pdf");

OR
using System.Net;

string pdfPath = Server.MapPath("~/SomePDFFile.pdf");
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(pdfPath);
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);


Process.Start("[PDFFileName].pdf");


If pdf file is on the server then:-
http://dotnetslackers.com/community/blogs/haissam/archive/2007/04/03/Downloading-Files-C_2300_.aspx[^]
 
Share this answer
 
You have to make sure that the account that your Web application is running under has at least read access to the directory where the pdf is located.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900