SIGN UP MEMBER LOGIN:    
ARTICLE

Create Folder using C#

Posted by Ankit Nandekar Articles | C# Language February 25, 2011
This article provides a few steps to create a folder which will be easy to follow.
Reader Level:



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:

folder.gif

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........

erver'>
Login to add your contents and source code to this article
Article Extensions
Contents added by Karthi Ramar on Dec 22, 2011
using System.IO;  
 
public void CreateFolder
{
string path = @"c:\folders\newfolder"; // or whatever  
if (!Directory.Exists(path))  
{  
   Directory.CreateDirectory(path);
}
}
share this article :
post comment
 

Hi,all My issue did not resolved yet since my question was How to create folder with folder path having more than 256 characters in it? i am able to create folder name with the path having 256 character in it.......but beyond that it says path is too long to accept.......Kindly suggest me the Solution....... Thanks in advance!

Posted by Ayyub khan May 02, 2011

i have already explained how to create subfolders in my article u can take help from my article.

Posted by Ankit Nandekar Apr 30, 2011

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

Posted by Ayyub khan Apr 29, 2011

no need of any special namespace for mappath can i see ur code i think there is a mistake in ur MapPath spelling.

Posted by Ankit Nandekar Apr 28, 2011

no need of any special namespace for mappath can i see ur code i think there is a mistake in MapPath spelling.

Posted by Ankit Nandekar Apr 28, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor