Search


Wednesday, March 11, 2009

How to create a folder and check if exist on the directory in c#

First i need to create a form with 1 textbox, button and a label in my page. I named the textbox as txtFolderName, button btnCheckandCreate and the label as lblMessage so now, I need to put the event in my button on click.. on the onclick eventon the button i need to put the code.

protected void btnCheckandCreate _Click(object sender, EventArgs e)
{
lblMessage.Text = "";

if (!System.IO.Directory.Exists(@"c:\" + txtFolderName.Text.ToUpper() + ""))
{
System.IO.Directory.CreateDirectory(@"c:\" + txtFolderName.Text.ToUpper() + "");
lblMessage.Text = txtFolderName.Text + " Folder successfully created.";
}
else
{
lblMessage.Text = txtFolderName.Text + " is not available";
}
}

No comments:

Post a Comment