Description:-
In
this article we will see about how to create folder on directory using directory class in dot net. here I have given simple example to read and easily
understand. I have used directory class to create folder on server. It’s pretty
easy to create folder in server directory in dot net using directory class.
Default.aspx:-
<div> <asp:TextBox ID="txtDirName" runat="server" /> <asp:Button ID="btnCreate" runat="server" Text="Create Folder" OnClick="btnCreate_Click" /> <asp:Label ID="lblMessage" runat="server" /> </div>
Default.aspx.cs:-
protected void btnCreate_Click(object sender, EventArgs e) { string directoryPath = Server.MapPath("~/") + txtDirName.Text; if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); lblMessage.Text = "Directory created"; } else lblMessage.Text = "Directory already exists"; }
Thanks for comments.....