Opening a pdf in .NET

.net, pdf

Solution

This is how we did it:

Put all the help folders in `%ApplicationFolder%/Help`. So, your pdf will have the path `%ApplicationFolder%/Help/Manual.pdf`. You can create a Help folder and put in your pdfs at your csproject, and attach the whole whole to the `csproject`, and set it to `copy always`. In this way you can make sure that the pdfs you copy to the `Help` folder are always the latest.

And copy everything ( minus the pdb files, of course) from your debug folder to your deploy folder.

Then, use `System.Diagnostics.Process.Start(pdfPath)` to start the help file when the help button is clicked. Here's how you can get the pdfPath:

Here's the code snippet:

public void Help_Click(object sender, System.EventArgs e)
{
    var appDir = Path.GetDirectoryName(Application.StartupPath);
    var helDir = Path.Combine(appDir, "Help");
    var pdfPath = Path.Combine(helDir, "Manual.pdf");

    System.Diagnostics.Process.Start(pdfPath);
}

You can test this in debug mode. Just press F5 ( remember to copy the pdf file to the debug folder) and you can get it

Problem

In the application we are working on we are trying to implement Help. We have a help pdf document and for the moment it has been deemed acceptable that when users click the help button it just opens the pdf. The application is a desktop app and the pdf file needs to be included in the install somehow and installed on the local machine. I essentially need two things: How would I add this pdf to the application so that it is available on the client machine after install? I can either put it in the resources of the project, or else I could put it in the Application Folder of the client setup installer. How would I open this pdf? I can either open this pdf by just launching the default pdf viewer for the file, or I can use the System.WinForms.WebBrowser tool to display it. However if I choose the second option, I am unsure of how to access the file stored in the resources or find it in the install folder. If you could please provide me with the code to do this (either in VB.Net or C#.Net) that would be great.

Original source