Take namespace system.data.sqlclient
and make a folder as Album
and on click event of button write this code:
string path = "";
string ab = "";
if (FileUpload1.HasFile)
{
string SFileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
int fileAppent = 0;
while (File.Exists(Server.MapPath("~/Album/" + SFileName)))
{
fileAppent++;
SFileName = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName)
+ fileAppent.ToString() + Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower();
}
path = Server.MapPath("~/Album/" + SFileName);
FileUpload1.PostedFile.SaveAs(path);
ab = "~/Album/" + SFileName;
SqlCommand cmd = new SqlCommand("insert into ImageURL(ImageUrl)values(@ImageUrl)", con);
cmd.Parameters.AddWithValue("@ImageUrl",ab);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}