How to open a PDF file that is also a project resource?

后端 未结 8 1875
星月不相逢
星月不相逢 2021-01-17 19:35

I have a PDF file that I have imported in as a resource into my project. The file is a help document so I want to be able to include it with every deployment. I want to be a

8条回答
  •  广开言路
    2021-01-17 19:54

    "ReferenceGuide" is the name of the pdf file that i added to my resources.

    using System.IO;
    using System.Diagnostics;
    
        private void OpenPdfButtonClick(object sender, EventArgs e)
        {
            //Convert The resource Data into Byte[] 
            byte[] PDF = Properties.Resources.ReferenceGuide;
    
            MemoryStream ms = new MemoryStream(PDF);
    
            //Create PDF File From Binary of resources folders helpFile.pdf
            FileStream f = new FileStream("helpFile.pdf", FileMode.OpenOrCreate);
    
            //Write Bytes into Our Created helpFile.pdf
            ms.WriteTo(f);
            f.Close();
            ms.Close();
    
            // Finally Show the Created PDF from resources 
            Process.Start("helpFile.pdf");
        }
    

提交回复
热议问题