How to create folder 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.CreateDirectory method will create a directory or subdirectory in specified path.
The below code block will create a folder with name Test in C Drive at root level.

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

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

Above example will create a directory if it is not exists.

Same way if we want to create a sub dir call Dir1 in C:\Test location then below code will do that

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

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