• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2450
  • Last Modified:

get the path of the C# console application

Running a C# console application, how can I get the application's directory?  I'm using visual studio 2008.
0
dhenderson12
Asked:
dhenderson12
  • 2
1 Solution
 
BalkisBrCommented:
Hi,

Environment.CurrentDirectory
0
 
käµfm³d 👽Commented:
Environment.CurrentDirectory can be modified.

A better way would be:
System.IO.Path.GetDirectoryName(
      System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);

Open in new window

0
 
williamcampbellCommented:
string path = System.IO.Directory.GetCurrentDirectory();
0
 
käµfm³d 👽Commented:
Again, current directory could be modified at some point, so GetCurrentDirectory could give inaccurate results.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now