Reputation: 29683
Right now I have this code which creates a folder in the specified path..
protected void btnAdd_Click(object sender, EventArgs e)
{
albname = txtName.Text.ToString();
try
{
string targetPath = Server.MapPath("..//Images//Albums//" + albname);
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
id = id + 1;
con.Open();
com = new SqlCommand("insert into album values(" + id + ",'" + albname + "')", con);
com.ExecuteNonQuery();
Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('Album Successfully added');", true);
con.Close();
txtName.Text = "";
}
else
{
Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('Album Name Already Exists!Please enter a different Name');", true);
}
}
catch (Exception ne)
{
error.Visible = true;
lblError.Text = ne.ToString();
}
}
This works well and fine for me now.. It creates a folder in specified path.. Now I am running this website in Localhost.. now when I host website in any server does the above code work?? or do is there any different way to create a folder when my website is Live on Internet.. Hope I will get any beautiful solution.
Upvotes: 0
Views: 2278
Reputation: 5223
It should work on your server also, as long as you have permissions to create a folder in the specified directory. Why don't you try it and see? If you get an error, make sure to post the full error message.
Upvotes: 2