0

I have a problem. I have a text file "hello.pdf" I put the file to the resource of the project and read the file

string filename = @"C:\Users\vivio\Documents\Visual Studio 2015\Projects\STool\STool\Resources\hello.pdf";
System.Diagnostics.Process.Start(filename);

I have a question: If I want packet STool to STool.exe, and then install this packet in the (D:)disk then I think I will not read file hello.pdf because in the code I set pathfile is "C:\Users\vivio\Documents\Visual Studio 2015\Projects\STool\STool\Resources\hello.pdf" Help me to resolve this problem, thanks all

2 Answers2

0

The following link is same with yours, maybe it would be helpful.

How to read embedded resource text file

Or this one. How to open a PDF file that is also a project resource?

0

First, copy the file to your project directory and include it in your project. In the file's properties, set the Copy to Output Directory to Copy Always. Now it will always copy to the build directory when you compile.

It will be saved to Directory.GetCurrentDirectory(), so to reference the file you will always be able to use:

string filename = Directory.GetCurrentDirectory() + "\\Resources\\hello.pdf";

Make sure the copy to output directory property is set to **Copy Always**

Moffen
  • 1,817
  • 1
  • 14
  • 34