With the use of the following code you can give the user the ability to enter a directory name, check to see if it already exists and if not then create the folder and upload the files there.
This article provides a few steps to create a folder which will be easy to follow.
Step 1
Design a form, then drag a TextBox from the toolbox, and then drag a Lable and a button; give the button the caption Create Folder. It should look like this:

Step 2
For the Create Folder button's Click event write the following code:
protected void Button1_Click(object sender, EventArgs e)
{
if (!System.IO.Directory.Exists(MapPath(MyTree.SelectedValue + "\\" + TextBox1.Text)))
{
System.IO.Directory.CreateDirectory(MapPath(TextBox1.Text));
Label1.Text = "Directory Created Successfully..........";
TextBox1.Text = "";
}
else
{
Label1.Text = "Directory Already Exist ..........";
}
}
Note: To create subfolder write this code
System.IO.Directory.CreateDirectory(MapPath(Foldername+ "\\" + TextBox1.Text));
Label1.Text = "Directory Created Successfully..........";
TextBox1.Text = "";
Foldername is the name of the folder in which you want to create subfolder.
Run your website........

Aseem BhardwajPosted Oct 19, 2016, 3:11 AM
How Create Folder at aspx page using C#????
Bhushan MehetrePosted Aug 9, 2013, 7:18 AM
Just remove 'MyTree.SelectedValue' and replace Directory will get created in your root of the project... You can edit it as per ur need.... :-)
lokenddra kumar lachoriyaPosted Mar 3, 2013, 12:35 AM
where is mytree what do the work mytree in this
Ni tarPosted Sep 28, 2012, 10:00 PM
if (!System.IO.Directory.Exists(MapPath(MyTree.SelectedValue + "\\" + TextBox1.Text))). Why do we need to use MyTree. What is the control in Design view. I am really new for that. Can you explain to me. Thanks.
Ni tarPosted Sep 28, 2012, 10:00 PM
if (!System.IO.Directory.Exists(MapPath(MyTree.SelectedValue + "\\" + TextBox1.Text))). Why do we need to use MyTree. What is the control in Design view. I am really new for that. Can you explain to me. Thanks.
Ni tarPosted Sep 28, 2012, 9:59 PM
if (!System.IO.Directory.Exists(MapPath(MyTree.SelectedValue + "\\" + TextBox1.Text))). Why do we need to use MyTree. What is the control in Design view. I am really new for that. Can you explain to me. Thanks.
Ayyub khanPosted Apr 29, 2011, 9:18 AM
Hi all, i would like to know how to create folders within folders up to 256 characters.........please if anyone has its code?....publish it Thanks in avance
sandeep sandyPosted Apr 27, 2011, 10:02 AM
during execution i am getting an error the name mappath does not exist in the content can u suggest me
Suthish NairPosted Feb 25, 2011, 4:38 AM
Before creating a Directory better always use Directory.Exists method to check the directory already exists or not... Instead of using MapPath(Foldername+ "\\" + TextBox1.Text), use Path.Combine method.