Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

C# Program to Get Complete Path of Current Directory

  • Last Updated : 28 Nov, 2021

Given a directory, now our task is to find the path of the given directory or current directory. So to this task, we use the GetCurrentDirectory() method of the Directory class. This method will return the complete path of the current directory. The result given by this method will not end with a backslash (\).

Syntax:

public static string GetCurrentDirectory();

Return: It will return a string that represents the path of the current directory. 

Exception: It will throw the following exceptions:

  • UnauthorizedAccessException: This exception occurs when the caller does not have the required permission.
  • NotSupportedException: This exception occurs when the operating system is Windows CE. It does not have the functionality of the current directory.

Example:

C#




// C# program to find the path of 
// the currect directory
using System;
using System.IO;
  
class GFG{
  
static void Main()
{
      
    // Finding the complete path of the current directory
    // Using GetCurrentDirectory() method
    Console.WriteLine("Current directory path: "
                      Directory.GetCurrentDirectory());
}
}

Output:

Current directory path: C:\Users\Sravan\ConsoleApplication12
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!