Skip to main content

Posts

Showing posts from June, 2019

how to create and delete folder using C#.

We can create, delete of check folder in c# using the Directory class. To create folder set the path(Location) on which you want to create the folder into  the variable, Here i am taking variable named folderPath. 
1. To create folder/directory.
string folderPath="E:\testing\";
  if (!Directory.Exists(folderPath))           {             Directory.CreateDirectory(folderPath);           }
2. To delete folder/directory. This method used when the folder you want to delete is empty.
string folderPath="E:\testing\test";
if (Directory.Exists(folderPath))             {                 Directory.Delete(folderPath);             }
3. To delete folder/directory with all the content.
string folderPath="E:\testing\test";
if (Directory.Exists(folderPath))             {                 Directory.Delete(folderPath,true);             }


Thanks!!!