how to save images in sqlserver again retrive from sqlserver using asp.net control
-
Hi I am trying to store the images using asp.net browser control ie, fileupload. .Its with store the images in to the databse where i used as sqlserver as backend. It store but, after that i am trying to retrive those images through listview from backend. But here i am getting no error but no images are there in images.I need the names of the images in the listview from backend while clicking a particular image it should be enlarge in image control.Thanks in advance.Please help me. In default.aspx.cs page: public partial class _Default : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DigitalSignageConnectionString2"].ConnectionString.ToString()); protected void Page_Load(object sender, EventArgs e) { } protected void BthSnd_Click(object sender, EventArgs e) { con.open(); SqlCommand mycommand = new SqlCommand("INSERT INTO Image_DiSig([image], [text],[path],[image1]) VALUES (@image, @text,@imgpath) ", con); string apppath = Request.PhysicalApplicationPath; FileUpload1.SaveAs(apppath + "images\\" + FileUpload1.FileName); string imgpath = apppath + "images\\" + FileUpload1.FileName; FileStream fs = File.OpenRead(imgpath); byte[] imagedata = new byte[fs.Length]; mycommand.Parameters.AddWithValue("@image", imagedata); mycommand.Parameters.AddWithValue("@text", TextBox1.Text); mycommand.Parameters.AddWithValue("@imgpath", apppath); mycommand.ExecuteNonQuery(); con.Close(); } public string FormatURL2(object strArgument) //used to get that image bytes(while tracing its picking that bytes but not converting into image) { return ("Default2.aspx?id=" + strArgument); } protected void LinkButton1_Click(object sender, EventArgs e) { SqlDataAdapter da = new SqlDataAdapter("select * from Image_DiSig",con); DataSet ds = new DataSet(); da.Fill(ds); ListView1.DataSource = ds; ListView1.DataBind(); } protected void ListView1_SelectedIndexChanged(object sender, EventArgs e) { Image1.ImageUrl = ListView1.SelectedValue.ToString(); } in default.aspx source page: <asp:ListView ID="ListView1" runat="server" onselectedindexchanged="ListView1_SelectedIndexChanged" SelectedIndex="0" > <LayoutTemplate> <div style="border:dotted 1px black;"> <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> </div> </LayoutTemplate> <ItemTemplate> <img alt="name" align="middle" height="50px" width="100px" name="Image1" src='<%# FormatURL2(DataBinder.Eval(Container.DataItem, "id")) %>' />
-
Hi I am trying to store the images using asp.net browser control ie, fileupload. .Its with store the images in to the databse where i used as sqlserver as backend. It store but, after that i am trying to retrive those images through listview from backend. But here i am getting no error but no images are there in images.I need the names of the images in the listview from backend while clicking a particular image it should be enlarge in image control.Thanks in advance.Please help me. In default.aspx.cs page: public partial class _Default : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DigitalSignageConnectionString2"].ConnectionString.ToString()); protected void Page_Load(object sender, EventArgs e) { } protected void BthSnd_Click(object sender, EventArgs e) { con.open(); SqlCommand mycommand = new SqlCommand("INSERT INTO Image_DiSig([image], [text],[path],[image1]) VALUES (@image, @text,@imgpath) ", con); string apppath = Request.PhysicalApplicationPath; FileUpload1.SaveAs(apppath + "images\\" + FileUpload1.FileName); string imgpath = apppath + "images\\" + FileUpload1.FileName; FileStream fs = File.OpenRead(imgpath); byte[] imagedata = new byte[fs.Length]; mycommand.Parameters.AddWithValue("@image", imagedata); mycommand.Parameters.AddWithValue("@text", TextBox1.Text); mycommand.Parameters.AddWithValue("@imgpath", apppath); mycommand.ExecuteNonQuery(); con.Close(); } public string FormatURL2(object strArgument) //used to get that image bytes(while tracing its picking that bytes but not converting into image) { return ("Default2.aspx?id=" + strArgument); } protected void LinkButton1_Click(object sender, EventArgs e) { SqlDataAdapter da = new SqlDataAdapter("select * from Image_DiSig",con); DataSet ds = new DataSet(); da.Fill(ds); ListView1.DataSource = ds; ListView1.DataBind(); } protected void ListView1_SelectedIndexChanged(object sender, EventArgs e) { Image1.ImageUrl = ListView1.SelectedValue.ToString(); } in default.aspx source page: <asp:ListView ID="ListView1" runat="server" onselectedindexchanged="ListView1_SelectedIndexChanged" SelectedIndex="0" > <LayoutTemplate> <div style="border:dotted 1px black;"> <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> </div> </LayoutTemplate> <ItemTemplate> <img alt="name" align="middle" height="50px" width="100px" name="Image1" src='<%# FormatURL2(DataBinder.Eval(Container.DataItem, "id")) %>' />