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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launching a PDF File Located on C: Drive From Code-Behind 1

Status
Not open for further replies.

JabbaTheNut

Programmer
Jul 29, 2002
176
US
LAY OF THE LAND: I am generating PDF files on the fly using Crystal Reports. I am saving these files on my server's C: drive in a directory called MyPDFs (i.e., C:\MyPDFs). The security on this directory allows full control to only administrators and the ASPNET user account (trying to prevent web users from directly accessing the files). I have a Win2K server with IIS 5.0 and I am using ASP.Net.

QUESTION: In the VB code behind my ASP.Net Web Form, I want to launch a PDF file located in the above mentioned directory ("C:\MyPDFs"). My VB code-behind assembles the proper PDF filename depending on what the user selects on the Web Form; however, for purposes of this question, assume the filename is MyFile.pdf ("C:\MyPDFs\MyFile.pdf"). What VB code do I use to launch this PDF file for the Web User? Game Over, Man!
 
I don't think you actually have to write any code for it.

If the user has adobe acrobat on their system, all you should need to do is redirect the user to that file, and acrobat will do the rest.

You may want to do something like display it in a new window, but otherwise there isn't any need for a "PDF Viewer Control" or something like that.

Thats the only thing with PDF: they're great, as long as you know your clients have acrobat installed. Maybe just add a link on the page to where they can download it? (I'm guessing though that since they want pdf, they probably have it anyway, in which case this entire paragraph is just taking up space on Tek-tips db. ;) )

Jack
 
here is the code I use

myReport cr = new myReport(); // this is the myReport.rpt
cr.SetDataSource(ds); // add a dataset

string strName = @"C:\MyPDFs\MyFile.pdf";

crDestination = new DiskFileDestinationOptions();
crDestination.DiskFileName = strName;
crExportOpt = cr.ExportOptions;
cr.ExportOptions.DestinationOptions = crDestination;
cr.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
cr.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

cr.Export();

// created the pdf file, now I need to view it in the browser

Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(strName);
Response.Flush();
Response.Close();


hth Daren J. Lahey
Just another computer guy...
 
You are mighty welcome!
Response.ContentType = "forums/purplestar";
*smirks*
Daren J. Lahey
Just another computer guy...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top