This Article defines how to create folder and
directory in ASP.NET.
Creating Folder in ASP.NET
In the designing form we take a Button control
and a Label control and Button named create Folder. The below example defines
that in simplest way.
The designing form looks like this.

Figure1
aspx code
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication37.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body style="height:
5px">
<form id="form1" runat="server">
<p>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
style="top:
56px; left:
204px; position:
absolute; height:
34px; width:
142px"
Text="Create
Directory"/>
</p>
<p>
<asp:Label ID="Label2" runat="server"
style="top:
99px; left:
244px; position:
absolute; height:
12px; width:
34px"
Text="Label"></asp:Label>
<asp:Button ID="Button3" runat="server" style="margin-bottom:
0px"
Text="Create Folder" onclick="Button3_Click1" />
</p>
<p>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</p>
</form>
</body>
</html>
VB code
Protected Sub Button3_Click1(ByVal
sender As Object,
ByVal e As EventArgs) Handles
Button3.Click
Dim pathToCreate As String = "D:\Rohatash2"
System.IO.Directory.CreateDirectory(pathToCreate)
Label3.Text = "Folder created"
Now creating directory in server
To create directory in server we use
server.Mappath class.
VB code
Private Sub CreateDirectoryIfNotExists(ByVal
NewDirectory As String)
Try
If Not
System.IO.Directory.Exists(NewDirectory)
Then
System.IO.Directory.CreateDirectory(NewDirectory)
Label2.Text =
"Directory Created"
Else
Label2.Text =
"Directory Exist"
End If
Catch _err As IOException
Response.Write(_err.Message)
End Try
End Sub
Protected Sub Button2_Click(ByVal
sender As Object,
ByVal e As EventArgs) Handles
Button2.Click
Dim NewDirectory As String = Server.MapPath("Rohatash
Kumar")
CreateDirectoryIfNotExists(NewDirectory)
End Sub
Now run the application and test it.