How to check folder is exists or not in CSharp

In the .NET Framework, the System.IO.Directory class provides some static methods for managing directories like creating new directories, moving directories from one path to another path, copying directories from one path to another path and deleting directories from the system. To use the Directory class related mathods you must import the System.IO namespace in your project.

Try it
 
			using System.IO;
		

The Directory.Exists method checks if directory is exist or not at given path.

The below code block checks a folder is exists in C Drive or not.

Try it
 
			string folderPath = @"C:\Test";

			if (!Directory.Exists(folderPath))
			{
				Directory.CreateDirectory(folderPath);
			}
		

Above example will create a directory if it is not exists in the C Drive.