How to set a working directory in a Visual Studio 2010 project?

My project is in C # Windows Forms. During debugging, I used the debugging folder as the working directory, but now that I will deploy my project, I need to specify the working directory. How to do it?

+4
source share
2 answers

You can install it programmatically using Environment.CurrentDirectory - but usually it is simply determined by how the program runs. For example, if you run the application by double-clicking on it, the working directory will be the one that contains the executable. If you run it from the command line, this will be the current console directory at that time.

Why does this matter in your code and what are you trying to install?

+5
source

Are you trying to write or read only files?

To read files you can add Application.StartupPath to your names.

For internal settings files to be read and written, use Application.UserAppDataPath .

For custom documents, use Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), Application.ProductName)

0
source

All Articles