My project is in C# Windows Forms. While debugging, I was using th开发者_运维技巧e debug folder as the working directory but now that I will deploy my project I need to specify a working directory. How do I do it?
You can set it programmatically with Environment.CurrentDirectory
- but normally it's simply determined by how the program is executed. For example, if you start the app by double-clicking on it, the working directory will be the one containing the executable. If you start it from the command line, it will be the current directory of the console at the time.
Why does it matter in your code, and what are you trying to set it to?
Are you trying to write or only read files?
For reading files, you may want to prepend Application.StartupPath
to your filenames.
For internal settings files that will be both read and written, use Application.UserAppDataPath
.
For user documents, use Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), Application.ProductName)
精彩评论