Opening a .pdf file as a window with a click of a button

In the current window that I have, I have a button. I want you to be able to click the button and open the .pdf file, which is located in the resources folder of this project. Is it easy to do?

Other methods that I examined use file paths, but file paths may not be the same all the time, but the .pdf file will always be in the resources folder. Is there any way to access this and open it at the click of a button?

Anything along the lines?

string filename = "instructions.pdf"; file.open(); 

Problem resolved with

 private void Button1_Click(object sender, EventArgs e) { string filename = "instructions.pdf"; System.Diagnostics.Process.Start(filename); } 

With .pdf instructions in the bin / debug folder where the program.exe file is located.

+8
source share
2 answers

To open a file using the default system view, you need to call

 System.Diagnostics.Process.Start(filename); 

But I did not understand the problem with the file path. If you need a relative path from the program's .exe file to the resources folder, you can add "Resources" or ".. \ Resources" (if the "Resources" folder is higher) to your file path.

Or you can add your pdf file to the project as an embedded resource, and then when you need to open it, you can save it in some temporary place using

 Path.GetTempPath() 

and open it.

+15
source

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

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

This will work when you click on a file in the Windows folder. If you cannot place the file path, you can copy the file from the resource to a temporary folder and use this path.

0
source

All Articles