I am new to Asp.Net i try to save image in a directory and the information in a data base, the information is saved successfully but the image is not saved in the directory.
My image upload code:
protected void Post_Click(object sender, EventArgs e)
{
con.Open(); if(Image.HasFile)
{
string filename = Path.GetFileName(Image.PostedFile.FileName);
string filesize = Image.FileBytes.Length.ToString();
string filepath = "../Posts/"+filename;
Image.SaveAs(Server.MapPath("../Posts/" + filename));
string qry1 = "insert into Images(Image_Name,Image_Size,Image_Path)values('" + filename + "','"+filesize+"','"+filepath+"')";
SqlCommand cmmd = new SqlCommand(qry1, con);
cmmd.ExecuteNonQuery();
}
string qry = "insert into Post(Post_Title,Post_Description,Post_Category,Post_Tag,Post_Date)values('" + Post_title.Text+ "','" + Description.Text + "','" + Category.Text + "','" + Tag.Text + "','" + DateTime.Now + "')";
SqlCommand cmd = new SqlCommand(qry,con);
cmd.ExecuteNonQuery();
con.Close(); }