In this Post Registration Form with Profile Image Asp.Net
Important Namespaces Used ---------------------------- using System.Data; using System.Data.SqlClient; ---------------------------- Static Variable Used ---------------------------- static String imagelink; ----------------------------- Saved Button Click Event ----------------------------- if(uploadimage()==true) { String query = "insert into profiledetail(rollno,sname,fname,mname,profileimage) values(" + TextBox1.Text + ",'" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + imagelink + "')"; String mycon = "Data Source=sk-pc; Initial Catalog=Class-College-Database; Integrated Security=true"; SqlConnection con = new SqlConnection(mycon); con.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = query; cmd.Connection = con; cmd.ExecuteNonQuery(); Label3.Text = "Registration Has Been Saved Successfully"; } ----------------------------- User Defined Method Used ----------------------------- private Boolean uploadimage() { Boolean imagesaved = false; if (FileUpload1.HasFile == true) { String contenttype = FileUpload1.PostedFile.ContentType; if (contenttype == "image/jpeg") { int filesize; filesize = FileUpload1.PostedFile.ContentLength; if (filesize <= 51200) { System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream); int height = img.Height; int width = img.Width; if (height == 200 && width == 200) { FileUpload1.SaveAs(Server.MapPath("~/ProfileImage/") + TextBox1.Text+".jpg"); Image1.ImageUrl = "~/ProfileImage/" + TextBox1.Text + ".jpg"; imagelink="ProfileImage/"+ TextBox1.Text + ".jpg"; imagesaved = true; } else { Label3.Text = "Kindly Upload JPEG Image in Proper Dimensions 200 x 200"; } } else { Label3.Text = "File Size exceeds 50 KB - Please Upload File Size Maximum 50 KB"; } } else { Label3.Text = "Only JPEG/JPG Image File Acceptable - Please Upload Image File Again"; } } else { Label3.Text = "You have not selected any file - Browse and Select File First"; } return imagesaved; } -------------------------------------