Opening a .pdf file in windows form through a button click

To open a file with a system default viewer you need call

System.Diagnostics.Process.Start(filename);

But I haven't understood the problem with a filepath. If you need a relative path from the program .exe file to a folder with resources, then you can add "Resources\" or "..\Resources\" (if Resources folder is higher) to your filepath.

Or you can add your pdf to a project as an embedded resource and then, when you need to open it, you can save it to some temporal location using

Path.GetTempPath()

and open it.


If you want to open the pdf file using Adobe Reader or similar application, you can use Process.Start function.

ProcessStartInfo startInfo = new ProcessStartInfo("pathtofile");
Process.Start(startInfo);

This will behave as you clicked on the file in Windows folder. If you cannot place the file path, then you can copy file from resource to a temporary folder and use that path.

Tags:

C#

Winforms

Pdf