Getting Application path in C#.Net


In an ideal C# application you can access application/executable path in following ways.

  • Application.StartupPath
  • System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location)
  • AppDomain.CurrentDomain.BaseDirectory
  • System.IO.Directory.GetCurrentDirectory()
  • Environment.CurrentDirectory
  • System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
  • System.IO.Path.GetDirectory(Application.ExecutablePath)

Following is a simple configuration file , where SQL SERVER information is stored and retrieved.

string app_path = AppDomain.CurrentDomain.BaseDirectory;
           
INIProfile inif = new INIProfile(app_path + "config.ini");

In this way you can used the application path in any part of your application.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.