Check if a folder exist in a directory and create them using C#

gymcode picture gymcode · Feb 1, 2012 · Viewed 226.4k times · Source

How can I check if directory C:/ contains a folder named MP_Upload, and if it does not exist, create the folder automatically?

I am using Visual Studio 2005 C#.

Answer

cycaHuH picture cycaHuH · Feb 1, 2012

This should help:

using System.IO;
...

string path = @"C:\MP_Upload";
if(!Directory.Exists(path))
{
    Directory.CreateDirectory(path);
}