How to get working directory

18 07 2010

In .NET Framework you can use Application.StartupPath() method to get the working directory. But it’s not supported in .NET Compact Framework. So, after read some article in the web, I found the working one. First, you must import System.Reflection namespace.

using System.Reflection;

Then use the Assembly.GetExecutingAssembly() and put the result in a string variable. The result will be like, ex:  “\Program Files\ComeUse”.

String dir = Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf(@"\"));



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: