Web Design that taps into the haromny and vision of your dreams.

How to Obtain the Current Application Directory in C#

Get current application directory when working with files

Written By on in C#

38 words, estimated reading time 1 minutes.

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.

Last updated on: Friday 23rd June 2017

 

Comments
Suneel

Suneel

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 to Suneel
HELLIC

HELLIC

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 to HELLIC
Kyle

Kyle

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

Thanks
~Kyle

Reply to Kyle
sandrar

sandrar

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

Reply to sandrar

 

Leave a Reply

Your email address will not be published.





If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.

Copyright © 2001-2018 Tim Trott, all rights reserved. Web Design by Azulia Designs

This web page is licensed for your personal, private, non-commercial use only.

Disclaimer, Privacy & LegalSitemapContact Me