开发者

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

开发者 https://www.devze.com 2023-03-12 04:03 出处:网络
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. Ho

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消