Darpan Pathak

Darpan Pathak

  • NA
  • 8
  • 4.3k

image upload

Nov 26 2012 10:32 AM
I am using a code to upload and save images into database and folder. Its works on localhost but when i uploded this forms on server its not working and giving 404 error. here is the link image.redmelonz.com i am using following code protected void btnSubmit_Click(object sender, EventArgs e) { //Get Filename from fileupload control string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName); //Save images into Images folder fileuploadimages.SaveAs(Server.MapPath("~/Images/"+filename)); //Getting dbconnection from web.config connectionstring //Open the database connection con.Open(); //Query to insert images path and name into database SqlCommand cmd = new SqlCommand("Insert into ImagesPath(ImageName,ImagePath) values(@ImageName,@ImagePath)", con); //Passing parameters to query cmd.Parameters.AddWithValue("@ImageName", filename); cmd.Parameters.AddWithValue("@ImagePath", "~/Images/" + filename); cmd.ExecuteNonQuery(); //Close dbconnection con.Close(); Response.Redirect("~/Default.aspx"); }

Answers (2)