Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. file upload

file upload

Scheduled Pinned Locked Moved ASP.NET
databasegraphicsquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    m dhu
    wrote on last edited by
    #1

    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

    S S 2 Replies Last reply
    0
    • M m dhu

      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

      S Offline
      S Offline
      sashidhar
      wrote on last edited by
      #2

      madhukk wrote:

      im trying get image to a image control

      Did You write code in

      madhukk wrote:

      Image1.ImageUrl = "de.aspx?id=0";

      To show the image..!

      LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

      1 Reply Last reply
      0
      • M m dhu

        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

        S Offline
        S Offline
        SayreCC
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups