try{if (!Directory.Exists(path)){// Try to create the directory.DirectoryInfo di = Directory.CreateDirectory(path);}}catch (IOException ioex){Console.WriteLine(ioex.Message);}
string root = @"C:\Temp";
string subdir = @"C:\Temp\Mahesh";
// If directory does not exist, create it.
if (!Directory.Exists(root)){
Directory.CreateDirectory(root);
}
string pathToNewFolder = System.IO.Path.Combine(parentFolderPath, "NewSubFolder");DirectoryInfo directory = Directory.CreateDirectory(pathToNewFolder);// Will create if does not already exist (otherwise will ignore)
public static class FileUploadExtension{public static void SaveAs(this FileUpload, string destination, bool autoCreateDirectory) {
if (autoCreateDirectory){var destinationDirectory = new DirectoryInfo(Path.GetDirectoryName(destination));
if (!destinationDirectory.Exists)destinationDirectory.Create();}
file.SaveAs(destination);}}