ASP.NET - Hyperlink -- Opening a local pdf file....

Asked By Sharad on 22-Oct-10 02:25 AM
I am trying to open a pdf file say from

The problem is, i am loading paths like the one above in a gridview using a list and making them hyperlink using RowDatabound event... The link are appearing but how do i assign the address of the local file to Navigate url attribute.. After pondering over internet for an hour and a half i didn't get any solution. So i need help guys.. I hope i am clear in stating my problem

Lalit M replied to Sharad on 22-Oct-10 02:30 AM
you can use following code sample

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());
Jatin Prajapati replied to Sharad on 22-Oct-10 02:33 AM
Rather to open such file from the location other that your web site, place that file in your web site's sub folder, and then try to access that file like below example
Suppose, you have a directoy in your web site is files and there you have placed the file somereport.pdf.
the you can access it like below in hyperlinke

<asp:HyperLink id="h1" runat="server" NavigateUrl="~/files/somereport.pdf" Text="Some Report" />

Sharad replied to Lalit M on 22-Oct-10 02:44 AM
Hello sir i have found the same solution on some site but i didn't find it useful... so i need to know how to specify navigate url attribute of local .pdf file so tht i could assign it to open it when its clicked...
Sharad replied to Jatin Prajapati on 22-Oct-10 08:02 AM
i figured it our myself... Anyway thanks for the suggestions...