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 18, 2016, 11:11 PM EDT
How Create Folder at aspx page using C#????
Bhushan MehetrePosted Aug 9, 2013, 3:18 AM EDT
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 2, 2013, 7:35 PM EST
where is mytree what do the work mytree in this
Ni tarPosted Sep 28, 2012, 6:00 PM EDT
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, 6:00 PM EDT
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, 5:59 PM EDT
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, 5:18 AM EDT
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, 6:02 AM EDT
during execution i am getting an error the name mappath does not exist in the content can u suggest me
Suthish NairTOP 100Posted Feb 24, 2011, 11:38 PM EST
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.