private void SaveProductImage() { if (UploadProductImage.PostedFile != null) { string filename = UploadProductImage.PostedFile.FileName.ToString(); string fileext = System.IO.Path.GetExtension(UploadProductImage.FileName); if (fileext != ".jpeg" && fileext != ".jpg" && fileext != ".png" && fileext != ".bmp") { Response.Write("<script>alert('invalid format');</script>"); } else if (filename.Length > 96) { Response.Write("<script>alert('large size');</script>"); } else if (UploadProductImage.PostedFile.ContentLength > 4000000) { Response.Write("<script>alert('size should not be more than 4MB');</script>"); } else { UploadProductImage.SaveAs(Server.MapPath("~/ProductImages/") + filename); } } }
protected void ButtonUpdate_Click(object sender, EventArgs e) { if (UploadProductImage.HasFile) { string imagePath = "~/images/" + UploadProductImage.FileName; UploadProductImage.SaveAs(Server.MapPath(imagePath).ToString()); SqlCommand cmd = new SqlCommand("UPDATE menuItems SET itemName = '" + TextBoxName.Text + "', itemPrice ='" + TextBoxPrice.Text + "', itemImage = '" + imagePath + "', itemDescription = '" + TextBoxBio.Text + "' WHERE itemID = " + Request.QueryString["ID"], con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); BindData(); } }