Open In App

C# Program to Get Complete Path of Current Directory

Last Updated : 21 Apr, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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 current 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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads