views:

61

answers:

3

What exactly is Working Directory in the properties of Visual Studio C# project.

I have see a project where I right click and go to Properties and then I go to Debug tab, it shows me Working Directory where Author of the code has specified folder in local machine. I want to know what does that working directory means and what kinds of file will it store in that directory.

Thank you in advance.

+4  A: 

Every process has a current Working Directory which is where all relative paths will be formed from. If not specified, this directory is the directory in which the active application started.

You can check which directory is set by calling:

System.IO.Directory.GetCurrentDirectory();

As mentioned above in a comment by @0xA3 this setting has no effect to your deployed product, it is is only for debugging.

Brian R. Bondy
Can you please give me a sample code using this relative path?
Suppose, I want to open a file and if I specifyFileStream fileStream = new FileStream(@"file.txt", FileMode.Open);and my Working directory is set to "c:\dir" then will it try to look for this file at "c:\dir\file.txt"?
@kinjalthehero: Yes that's correct.
Brian R. Bondy
Thank you for your help.
+1  A: 

The working directory of a project (and any Windows program in general) is the default place in which a program is looking up it's files. For example: My program has working directory C:\dir and tries to open test.txt, it would look in C:\dir\test.txt.

So every opened file will be opened relative to the working folder.

Laurens Ruijtenberg
Thank you for the explanation with an example...
+1  A: 

I think it will store nothing there, unless you add/write code in your application which explicitly creates files, either explicitly in the application's working directory, or implicitly specifying only a filename without specifying a directory at all.

ChrisW