Wednesday, July 4, 2012

Create Folder on Server at Runtime Using Asp.Net

.Aspx Code
------------------------------
<div>
    Directory Name : <asp:TextBox ID="txtdir" runat="server"></asp:TextBox>
        <br />

    <asp:Button ID="btn" runat="server" Text="Create Directory" onclick="btn_Click" />
        <br />

    <asp:Label ID="lbl" runat="server" ></asp:Label>
    </div>
-------------------------------

.Aspx.Cs

-------------------------------

using System.IO;

protected void btn_Click(object sender, EventArgs e)
    {
        string Path = Server.MapPath("~/") +txtdir.Text.Trim();
        if (!Directory.Exists(Path))
        {
            Directory.CreateDirectory(Path);
            lbl.Text = "Directory created successfully";
        }
        else
            lbl.Text = "Directory already exists";
    }

No comments:

Post a Comment