Application Current Working Folder  
Author Message
Steve98796





PostPosted: .NET Base Class Library, Application Current Working Folder Top

Hi

I want to be able to get hold of the name of the current working folder that my application is running in.

I tried Application.StartupPath but this always gives the folder the executable was loaded from.

It is possible for example on a shortcut to set a Start In folder which is not where the executable is loaded from but is the current working folder.

Thanks

 



.NET Development6  
 
 
Mike Danes





PostPosted: .NET Base Class Library, Application Current Working Folder Top

You can use System.Environment.CurrentDirectory or System.IO.Directory.GetCurrentDirectory() to get the current working folder.

 


 
 
Steve98796





PostPosted: .NET Base Class Library, Application Current Working Folder Top

Thank you
 
 
RizwanSharp





PostPosted: .NET Base Class Library, Application Current Working Folder Top

So simple,

string currentDirectory = Environment.CurrentDirectory;]

I hope this will work.

Best regards,

Rizwan aka RizwanSharp



 
 
boban.s





PostPosted: .NET Base Class Library, Application Current Working Folder Top

There are many ways of getting application folder. Some are good some are bad. But the main difference between those methods is that some are constant and some are changeable. I will sort four methods in order from best to worse:
AppDomain.CurrentDomain.BaseDirectory  (best)
Application.StartupDirectory  good but requires System.Windows.Forms
Environment.CurrentDirectory  (bad because you can't be sure that always will return the same folder path)

also reflection can be used 'this.GetType.Assembly.Location' to get current directory, but mainly it is used for getting running directory of some library.