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. General Programming
  3. C#
  4. Saving Image to a file from database.

Saving Image to a file from database.

Scheduled Pinned Locked Moved C#
database
2 Posts 2 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.
  • S Offline
    S Offline
    Syed Mujtaba Hassan
    wrote on last edited by
    #1

    Hi there, I am trying to save an Image from a database to a file but it only save the following to the file "System.Byte[]".

    fileWriter.Write(dsExportDataTypes.Tables[0].Rows[i]["ATTACHMENT"]);

    fileWriter is an object of StreamWriter Class.

    Mujtaba "If both of us are having one apple each and we exchange it, at the end we both will have one apple each. BUT if both of us are having one idea each and we exchange it, at the end both of us will be having two ideas each."

    P 1 Reply Last reply
    0
    • S Syed Mujtaba Hassan

      Hi there, I am trying to save an Image from a database to a file but it only save the following to the file "System.Byte[]".

      fileWriter.Write(dsExportDataTypes.Tables[0].Rows[i]["ATTACHMENT"]);

      fileWriter is an object of StreamWriter Class.

      Mujtaba "If both of us are having one apple each and we exchange it, at the end we both will have one apple each. BUT if both of us are having one idea each and we exchange it, at the end both of us will be having two ideas each."

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      You're using the wrong class. StreamWriter is used for writing character data to streams. To save an image to a file, you need to use a class that will handle a binary stream of data. FileStream[^] is the most appropriate class to use. Your code would look like:

      myFileStream.Write((byte[])dsExportDataTypes.Tables[0].Rows[i]["ATTACHMENT"]);

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      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