file upload
-
hi all., this is how i inserted images into sql.. and displayed thumbnail in image control..
// button click
byte[] img = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile postfile = FileUpload1.PostedFile;
postfile.InputStream.Read(img, 0, (int)FileUpload1.PostedFile.ContentLength);
System.Drawing.Image img12 = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
SqlCommand cmd = new SqlCommand("insert into image11 (type,name,length,byte) values(@type,@name,@length,@byte)", cnn);
cmd.Parameters.Add("@type", SqlDbType.VarChar).Value = FileUpload1.PostedFile.ContentType;
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = FileUpload1.PostedFile.FileName;
cmd.Parameters.Add("@length", SqlDbType.VarChar).Value = FileUpload1.PostedFile.ContentLength;
cmd.Parameters.Add("@byte", SqlDbType.Image, img.Length).Value = img;
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
DataTable dtTemp = new DataTable("TempImage");//Creating temprory data table which will store image information
dtTemp.Columns.Add("Image", System.Type.GetType("System.Byte[]"));//Byte Image column
DataRow dr = dtTemp.NewRow();
dr[0] = img;//storing binary image information in table.
dtTemp.Rows.Add(dr);
Session["dt"] = dtTemp;//storing temprory table in seesion.
Image1.ImageUrl = "de.aspx?id=0";im trying get image to a image control but im unable to retrive that image from database i tried using handler.ashx
-
hi all., this is how i inserted images into sql.. and displayed thumbnail in image control..
// button click
byte[] img = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile postfile = FileUpload1.PostedFile;
postfile.InputStream.Read(img, 0, (int)FileUpload1.PostedFile.ContentLength);
System.Drawing.Image img12 = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
SqlCommand cmd = new SqlCommand("insert into image11 (type,name,length,byte) values(@type,@name,@length,@byte)", cnn);
cmd.Parameters.Add("@type", SqlDbType.VarChar).Value = FileUpload1.PostedFile.ContentType;
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = FileUpload1.PostedFile.FileName;
cmd.Parameters.Add("@length", SqlDbType.VarChar).Value = FileUpload1.PostedFile.ContentLength;
cmd.Parameters.Add("@byte", SqlDbType.Image, img.Length).Value = img;
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
DataTable dtTemp = new DataTable("TempImage");//Creating temprory data table which will store image information
dtTemp.Columns.Add("Image", System.Type.GetType("System.Byte[]"));//Byte Image column
DataRow dr = dtTemp.NewRow();
dr[0] = img;//storing binary image information in table.
dtTemp.Rows.Add(dr);
Session["dt"] = dtTemp;//storing temprory table in seesion.
Image1.ImageUrl = "de.aspx?id=0";im trying get image to a image control but im unable to retrive that image from database i tried using handler.ashx
-
hi all., this is how i inserted images into sql.. and displayed thumbnail in image control..
// button click
byte[] img = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile postfile = FileUpload1.PostedFile;
postfile.InputStream.Read(img, 0, (int)FileUpload1.PostedFile.ContentLength);
System.Drawing.Image img12 = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
SqlCommand cmd = new SqlCommand("insert into image11 (type,name,length,byte) values(@type,@name,@length,@byte)", cnn);
cmd.Parameters.Add("@type", SqlDbType.VarChar).Value = FileUpload1.PostedFile.ContentType;
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = FileUpload1.PostedFile.FileName;
cmd.Parameters.Add("@length", SqlDbType.VarChar).Value = FileUpload1.PostedFile.ContentLength;
cmd.Parameters.Add("@byte", SqlDbType.Image, img.Length).Value = img;
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
DataTable dtTemp = new DataTable("TempImage");//Creating temprory data table which will store image information
dtTemp.Columns.Add("Image", System.Type.GetType("System.Byte[]"));//Byte Image column
DataRow dr = dtTemp.NewRow();
dr[0] = img;//storing binary image information in table.
dtTemp.Rows.Add(dr);
Session["dt"] = dtTemp;//storing temprory table in seesion.
Image1.ImageUrl = "de.aspx?id=0";im trying get image to a image control but im unable to retrive that image from database i tried using handler.ashx
Hi Madhukk, Please visit this site. http://www.aspsnippets.com/post/2009/02/21/Display-Images-from-Database-using-ASPNet.aspx
Hope this one can help. Thanks Hi, Please select Good Question if my answer are fit to your Question.