[EDIT]
I try to open a file from a folder in my base directory.
From the solution explorer, there is a folder “Docs” and a pdf file in it (tempPDF.pdf).
That will corresponds to a folder in my Project Folder. (e.g. Project\Docs) this is in the save level as bin and properties folders.
String assemblyPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
Process proc = new Process();
proc.StartInfo = new ProcessStartInfo()
{
FileName = assemblyPath + "\\Docs\\tempPDF.pdf"
};
proc.Start();
I have already changed the Build Action to “Resource” and Copy to Output Directory to “Copy Always”. Yet, the pdf file is not copies to the bin, nor the file can be specified by the program. I clean, build and rebuild the solution.
Path kept pointing to bin\Debug folder because this is where the executables is located but the files are location at the same level as bin.
I can simply specific my image in XAML by a path like “Images\img.png”, and it will find the image relatively.
This is supposed to be a very simple question – open a PDF from a mouse click.
[EDIT – with answer]
Have to change Build Action to “Embedded Resource”, NOT “Resource” (Resource only copy a empty folder without the files). I don’t know why though.
First, there is no XAML solution for that. We cannot execute a process without code-behind assistance.
The URI you show is relative to the current assembly.
You can use the assembly directory path then append the relative path of the file.
It can be something like this:
If you want to put your documents in the application folder, you can also use that directory path instead of the assembly path: