Like it

Sunday, July 10, 2011

How to CreateFolder in C# (.NET) / How to Create a Directory in C# (VB.NET)

How to check if a directory exists in C# / How to check if a folder exists in C#

Many times backups are created in a new folder with name as date etc. The following snippet checks if directory exists in the particular path and creates it

private static void CreateFolder() 
//This example creates a new folder under MyDocuments 
string folderName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string userName = Environment.UserName; 
folderName = Path.Combine(folderName, userName); 
if (Directory.Exists(folderName) == false) 
Directory.CreateDirectory(folderName); 
}  

How to combine two paths in .NET

The example combines two paths using Path.Combine method.



No comments:

Post a Comment