RSS Feed

How to Create and Delete Folder Dynamically in ASP.NET

December 19, 2011 by Sourabh Sharma

As you all know while developing a big application in asp.net everybody use Folders inside the application to keep the files separate. The Folder make an important for the developer sometime. In this Article I will tell you that how can you create as well as delete the folders inside your asp.net application. First to create an application you need to import “System.IO” Namespace. Because to create and remove folders we use the “DirectoryInfo” Class. As you will study this article later you will get the code with example about creating and deleting folder at runtime.

 


Free Download:
Create and Delete Folder: Demo Project

 Code of Web Page

1. Global Variables:

string  path1 = "D:\\www.dotnetaid.com\\asp.net helper\\Web Project
 \\37. Delete Folder\\DeleteFolder\\Image";
string  path2 = "D:\\www.dotnetaid.com\\asp.net helper\\Web Project\\
 37. Delete Folder\\DeleteFolder\\Video";

2. Create Folder Code:

protected void btnCreateFolder_Click(object sender, EventArgs e)
    {

        DirectoryInfo di = Directory.CreateDirectory(path1);
        DirectoryInfo di2 = Directory.CreateDirectory(path2);
    }

3. Delete Folder Code:

protected void btnDeleteFolder_Click(object sender, EventArgs e)
    {
        DirectoryInfo di = Directory.CreateDirectory(path1);
        di.Delete();
    }


No Comments »

No comments yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>