Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How to open a PDF in my project resources?

Tags:

c#

pdf

I have a WinForms GUI that has a 'help' context menu. When clicked, I would like to open the user manual for the application. The manual is a pdf which is stored within the application resources.

Question: How do I open this for the user?

Code I'm working with

System.Diagnostics.Process process = new System.Diagnostics.Process();
bool adobeInstall = false;
RegistryKey adobe = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe");
if (adobe != null)
{
    RegistryKey acroRead = adobe.OpenSubKey("Acrobat Reader");
    if (acroRead != null)
        adobeInstall = true;
}

if (adobeInstall == true)
{
    ///Open the pdf file??
}
like image 387
stackoverflow Avatar asked Feb 17 '23 00:02

stackoverflow


2 Answers

string locationToSavePdf = Path.Combine(Path.GetTempPath(), "file name for your pdf file.pdf");  // select other location if you want
File.WriteAllBytes(locationToSavePdf,Properties.Resources.nameOfFile);    // write the file from the resources to the location you want
Process.Start(locationToSavePdf);    // run the file
like image 90
coolmine Avatar answered Feb 23 '23 06:02

coolmine


Try this (you need just a path to the PDF file, no need to add it to the resource):

using System.Diagnostics;

Process.Start(“Path_of_PDFFile”)
like image 26
Leo Chapiro Avatar answered Feb 23 '23 07:02

Leo Chapiro