0

I just published my project and he can't find my Manual file. I'm using this for getting the file:

    private void btnHelp_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start(Environment.CurrentDirectory + @"\Handleiding Lijmlijnen tekenen.pdf");
    }

pretty straight forward, and it works when I'm debugging. But when I published it, it shows an error that he can't find that specific file. It points to this location: C:\Users\Bart\Documents\Visual Studio 2015\Projects\TestDXFlibrary\TestDXFlibrary\bin\Debug\Handleiding Lijmlijnen tekenen.pdf

Giulio Vian
  • 8,248
  • 2
  • 33
  • 41
Bart
  • 717
  • 1
  • 9
  • 28

1 Answers1

2

The "current directory" in release can change (and most probably will change). Display a simple dialog with your path to check if it is correct. Check if the file is in there by copying and pasting the path to File Explorer.

If you are trying to deliver a pdf file along with the project, change the properties of the pdf file in your project file:

  • set Copy To Output Directory to Copy always/Copy if newer
  • set Build Action to Content

BTW. Better would be to use Path.Combine method, like that.

piotrwest
  • 2,098
  • 23
  • 35
  • When I use Path.Combine it only takes the second half, He doesn't seem to like the Environment.CurrentDirectory part – Bart Aug 25 '15 at 08:47
  • And the file isn't in that location. So how can I include my manual to my project? – Bart Aug 25 '15 at 08:53
  • It should work fine: https://dotnetfiddle.net/Widget/OzM3Aa. If you have it in project in Visual Studio, the simplest way would be set it Copy To Output Directory to "Copy always"/"Copy if newer": http://stackoverflow.com/questions/4596508/vs2010-how-to-include-files-in-project-to-copy-them-to-build-output-directory-a – piotrwest Aug 25 '15 at 08:56
  • Ive changed the files to Copy always and still it isn't working. – Bart Aug 25 '15 at 09:41
  • In Release or in Publish? What sort of publish are you doing? What do you have in mind that "it isn't working"? Do you get any error messages? – piotrwest Aug 25 '15 at 09:48
  • Well it isn't working as in it isn't responding like it should as in debug, it won't open my manual file(pdf). And I just simply publish it. A simple setup file to install the programm. (Build->Publish) – Bart Aug 25 '15 at 09:50
  • 1
    Ok, just change the "Build Action" property of the pdf file to "Content". – piotrwest Aug 25 '15 at 10:03