How do I get current working directory?

Category: System, viewed: 2K time(s).

If you want to get the current directory of your running program you can use the Environment.CurrentDirectory. This will give you the fully qualified path to the current working directory. You might need to as the path to read you configuration file or log files for instance.

using System;

namespace Kodecsharp.Example.System
{
    class CurrentDirectory
    {
        public static void Main(string[] args)
        {
            //
            // Get the fully qualified path of the current working 
            // directory
            //
            string currentDir = Environment.CurrentDirectory;
            Console.WriteLine("Current Directory: " + currentDir);

            Console.ReadLine();
        }
    }
}
Powered by Disqus