Sunday, 10 March 2013
How to make a Folder/Directory in Asp.net with C-Sharp
http://aspnetgeeks.blogspot.com/p/aspnet.html
<div style=" float:left; position:relative; clear:left">
<%-- <h2 style="color:Navy">asp.net example: create directory</h2> --%>
<asp:Label ID="Label1" runat="server" Font-Size="Medium" ForeColor="SeaGreen"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Font-Size="20px" ForeColor="Red"></asp:Label>
<asp:Label ID="Label4" runat="server" Font-Size="20px" ForeColor="Red"></asp:Label>
<br /><br />
<asp:Label ID="Label3" runat="server" Text="Directory Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br /><br />
<asp:Button ID="btnCreateDirectory" runat="server" Font-Bold="true" ForeColor="HotPink" Text="Create Directory" OnClick="btnCreateDirectory_Click" />
</div>
aspx Code
<div style=" float:left; position:relative; clear:left">
<%-- <h2 style="color:Navy">asp.net example: create directory</h2> --%>
<asp:Label ID="Label1" runat="server" Font-Size="Medium" ForeColor="SeaGreen"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Font-Size="20px" ForeColor="Red"></asp:Label>
<asp:Label ID="Label4" runat="server" Font-Size="20px" ForeColor="Red"></asp:Label>
<br /><br />
<asp:Label ID="Label3" runat="server" Text="Directory Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br /><br />
<asp:Button ID="btnCreateDirectory" runat="server" Font-Bold="true" ForeColor="HotPink" Text="Create Directory" OnClick="btnCreateDirectory_Click" />
</div>
Code Behind File
protected void btnCreateDirectory_Click(object sender, System.EventArgs e)
{
string appPath = Request.PhysicalApplicationPath.ToString();
DirectoryInfo newDirectory = new DirectoryInfo(appPath + TextBox1.Text);
string path = Server.MapPath("~/" + TextBox1.Text);
try
{
if (!Directory.Exists(path))
{
newDirectory.Create();
SqlConnection conn = DataAccess.GetConnected();
SqlCommand cmd = new SqlCommand("AddCheckFolder", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@folder_name",TextBox1.Text);
cmd.Parameters.AddWithValue("@CreatedDate",DateTime.Now.ToString());
int result= cmd.ExecuteNonQuery();
if (result != 0)
{
Label4.Text = "Folder Added in Database Successfully";
}
else
{
Label4.Text = "Unfortunately Folder Can't added in Database";
}
}
else
{
Label2.Text = "Folder Already Exists";
}
}
catch (Exception ex)
{
Label2.Text = "An error occured when creating a directory!";
}
0 comments :
Post a Comment