Sunday 27 September 2009

Check if folder exists and return a message in C#

The form I have used for this example contains one label and one button. The code checks the location you specify and then prints a message in the label to tell you if the directory exists.

using System.IO;

private void button1_Click(object sender, EventArgs e)
{
string foldername;
string path;
string combinedpath;
{

foldername = "testfolder";
path = @"C:\blogexample";
combinedpath = path + @"\" + foldername;

if
(Directory.Exists(combinedpath))
label1.Text = "Directory exists";
else
label1.Text = "Directory doesn't exist";

}

No comments:

Post a Comment