0

I require some assistance, I have a pdf file that is located on a ftp location.

What i want to do, is on a button click i want to retrieve the pdf file and display it on a new tab.

Please assist on how to accomplish this task.

Thanks in advance.

johnnie
  • 1,837
  • 5
  • 23
  • 36
  • You may want to consider embedding your PDF in an iframe: http://stackoverflow.com/questions/291813/best-way-to-embed-pdf-in-html – dana Aug 04 '12 at 15:10

2 Answers2

2

One approach would be to make a web request to download the file and then pass the download stream along to the ASP.NET response stream. I haven't compiled or executed this code, but it might look something like this:

WebRequest request = HttpWebRequest.Create("ftp://ftp.yoursite.com/yourfile.pdf");
request.Credentials = new NetworkCredential("ftpuser","ftppassword");

// Get the response
WebResponse response = request.GetResponse();
StreamReader responseStream = new StreamReader(response.GetResponseStream());

// Send the response directly to output
Response.ContentEncoding = responseStream.CurrentEncoding;
Response.ContentType = "application/pdf";
Response.Write(responseStream.ReadToEnd());
Response.End();
Matt Varblow
  • 7,651
  • 3
  • 34
  • 44
1

Just use the HTML anchor tag ("a" tag). In the href attribute put the FTP address of the PDF file (eg. ftp://example.com/file.pdf). To open in a new window you should also specify a target attribute with the value "_blank".

Example:

<a href='ftp://example.com/file.pdf' target='_blank'>Click here to open the PDF file</a>

Leonel Machava
  • 1,501
  • 11
  • 19
  • This assumes the browser can handle the pdf or has a plug-in that can handle it. Otherwise, the user may be prompted to save/download the file. – Steve Wellens Aug 04 '12 at 15:05
  • 1
    Normally if the browser can handle the pdf it may display it. Otherwise it will give the option to download to the file system. – Leonel Machava Aug 04 '12 at 15:07