<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Img.aspx.cs" Inherits="Img" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="btnUpload" runat="server" onclick="btnUpload_Click" Text="Upload Image" /> <br /> <br /> <asp:FileUpload ID="FileUpload1" runat="server" /> <br /> <br /> <asp:Button ID="btnRetrieve" runat="server" onclick="btnRetrieve_Click" Text="Retrieve Image" /> <br /> <br /> <asp:Image ID="Image1" runat="server" /> <br /> <asp:GridView ID="GridView1" runat="server" onselectedindexchanged="GridView1_SelectedIndexChanged"> </asp:GridView> <br /> </div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </form> </body> </html>
protected void btnUpload_Click(object sender, EventArgs e) { FileUpload img = (FileUpload)FileUpload1; if (img.HasFile && img.PostedFile != null) { HttpPostedFile File = FileUpload1.PostedFile; byt = new Byte[File.ContentLength]; File.InputStream.Read(byt, 0, File.ContentLength); SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=adventureworks;Integrated Security=True"); con.Open(); SqlCommand cmd = new SqlCommand("insert into ImageStore values(@ID,@ImageContent)", con); cmd.Parameters.AddWithValue("@ID",TextBox1.Text); cmd.Parameters.AddWithValue("@ImageContent", byt); cmd.ExecuteNonQuery(); con.Close(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)