public partial class Default3 : System.Web.UI.Page { SqlConnection con = new SqlConnection("Data Source=ADMIN-PC;Initial Catalog= Official;Integrated Security=true;"); protected void Page_Load(object sender, EventArgs e) { } protected void Button2_Click(object sender, EventArgs e) { string path = Server.MapPath("Image/"); if(FileUpload1.HasFile) { string ext=Path.GetExtension(FileUpload1.FileName); if (ext== ".jpg" || ext== ".png") { FileUpload1.SaveAs(path+FileUpload1.FileName); string name="~/Image/"+FileUpload1.FileName; string s = "insert into immage values('"+TextBox1.Text.Trim()+"','"+name+"')"; SqlCommand cmd= new SqlCommand(s,con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); Response.Write("Your file has been uploaded"); } else { Response.Write("You can upload only jpg and png files"); } } else { Response.Write("Please select a file"); } } }
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Panel ID="panel1" runat="server"> <div> <br /> <asp:Label ID="Label1" runat="server" Text="Name" Visible="False"> <asp:TextBox ID="TextBox1" runat="server" Visible="False"> <asp:Button ID="Button2" runat="server" onclick="Button2_Click" style="top: 345px; left: 641px; position: absolute; height: 26px; width: 56px" Text="Submit" /> <div id="Imagediv"> style="width: 319px; removed 62px; removed 507px; removed: absolute; height: 275px"> <asp:FileUpload ID="FileUpload1" runat="server" style="width: 217px; top: 239px; left: 60px; position: absolute; height: 22px" /> </div> </div> </form> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)