Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you hyperlink a pdf from from datagrid control?

Status
Not open for further replies.

Ken011

MIS
Oct 13, 2006
66
0
0
US
Hello again, all:

So right now, using a datagrid, each pdf file is listed with its associated records:

<asp:HyperLinkColumn HeaderText="<font color=white>PDF</font>" DataNavigateUrlField="filename" DataNavigateUrlFormatString="downloadTracker.aspx?id={0}" DataTextField="filename" Target="_new" />

I want to be able to click on this pdf file called filename and have it open in an adobe reader.

I am so lost as to what to do. Can someone, please assist?

Thanks in advance
 
You have a couple of options, the easiest of which is to just do a response.redirect in the "downloadTracker" page to the pdf based on whatever querystring value is passed to it.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
if it's a real file you could point the url directly to the file. If you're dynamically generating the report I would suggest a http handler instead of a webform.

url example: viewpdf.ashx?pdfid=1
Code:
public class viewpdf : ihttphandler
{
   public void ProcessRequest(HttpContext context)
   {
      int id = int.Parse(context.Request["pdfid"]);
      byte[] bytes = PDF.Generate(id);

      context.Response.ContentType = "application/pdf";
      context.Response.Headers.Add("content-disposition", "inline;filename=mtdocument.pdf");
      context.Response.BinaryWrite(bytes);
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
thank you so much jmeckley,

Your solution is the best I have seen so far.

I have solved it as far as opening a PDF file associated with a record.

However, I like your method, if I can make it work because it allows me to use additional code to track what files are downloaded, etc.

The question that I have is, I am getting PDF not declared on this line:

byte[] bytes = PDF.Generate(id);

How do I resolve it?

Also, what does this mean:

"inline;filename=mtdocument.pdf"

???

Thanks a bunch
 
PDG.Generate is just a function i made up. in it's place you would have an object which fetches the document as a byte array.

inline means the file will open automatically for the user. the other option is attachment which will prompt users to Save, Open, Cancel the operation.

filename=doc.pdf is the name you want to associate with the file. it could be anything you want.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top