C# Tips: Create Directory if not exist


Do you know that , In C#.Net it is possible to check directory is exist on a particular path on a system using System.IO library.

This will be great help when we want to implement the software on a system, with folder structure we are using to store out put or backup folder structure. The following simple function may help you

using System.IO;
public static void AutoCreateDirectory(string dpath)
{
try
{
if (!Directory.Exists(dpath))
{
Directory.CreateDirectory(dpath);
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString());
}
}
view raw autocreate_dir.cs hosted with ❤ by GitHub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.