protected void Button2_Click(object sender, EventArgs e) { try { TextBox2.Text = Label3.Text; string path = Server.MapPath("Images/"); MyConn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True"; if (FileUpload1.HasFile) { string ext = Path.GetExtension(FileUpload1.FileName); if (ext == ".jpg" || ext == ".png") { FileUpload1.SaveAs(path + FileUpload1.FileName); string name = "~/images/" + FileUpload1.FileName; string s = "insert into upload values ('" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + name + "')"; MyComm = new SqlCommand(s, MyConn); MyConn.Open(); MyComm.ExecuteNonQuery(); MyConn.Close(); Response.Write("Your file has been uploaded"); } else { Response.Write("You can only upload jpg or png file"); } } else { Response.Write(" Please select a file"); } } catch { } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)