Learning never exhausts the mind

Last Updated by

From time to time you may need to access a file within the current application directory .Net provides a property that is set to the absolute path to the application executable, and a method can be used to extract the folder name.
using System.IO;
using System.Windows.Forms;

string appPath = Path.GetDirectoryName(Application.ExecutablePath);

Console Application project types will have to manually add a reference to the System.Windows.Forms assembly for the Application object to be exposed.

4 thoughts on “How to Obtain the Current Application Directory in C#
  • 11th May 2012 at 12:00 am

    Some other way to get current directory path.
    1) Application.StartupPath
    2) Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)

    3) AppDomain.CurrentDomain.BaseDirectory

    4) Path.GetDirectoryName( Environment.GetCommandLineArgs()[0])
    5) System.IO.Directory.GetCurrentDirectory()
    6) Environment.CurrentDirectory

    For More information join
    http:mycodelogic.com

    Reply
  • 18th May 2011 at 12:00 am

    There is no App.path in C#, that is current working Folder of project.

    This is rediculous library provided by Microsoft.
    Helll is well

    Reply
  • 6th July 2010 at 12:00 am

    Hey, thanks for the help!  :)  Finally was able to continue on coding!

    Thanks
    ~Kyle

    Reply
  • 10th September 2009 at 12:00 am

    Hi! I was surfing and found your blog post... nice! I love your blog.  :)  Cheers! Sandra. R.

    Reply

Leave a Reply

Fields marked with * are mandatory.

We respect your privacy, and will not make your email public. Hashed email address may be checked against Gravatar service to retrieve avatars. This site uses Akismet to reduce spam. Learn how your comment data is processed.