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. Writing byte stream

Writing byte stream

Scheduled Pinned Locked Moved C#
data-structuresquestion
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.
  • G Offline
    G Offline
    gauthee
    wrote on last edited by
    #1

    Hi, Iam trying to open a word document using filestream and thereby put the data in byte array by reading the filestream. Now, i want to write back the byte stream to a file like doc file, would there be any complexities by doing this? If the document has some images can it be written back to a file? code is as follows: //for reading FileStream fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Read); long len; len = fileStream.Length; Byte[] fileAsByte = new Byte[len]; fileStream.Read(fileAsByte, 0, fileAsByte.Length); same logic for writing too Thanks,

    gauthee

    L 1 Reply Last reply
    0
    • G gauthee

      Hi, Iam trying to open a word document using filestream and thereby put the data in byte array by reading the filestream. Now, i want to write back the byte stream to a file like doc file, would there be any complexities by doing this? If the document has some images can it be written back to a file? code is as follows: //for reading FileStream fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Read); long len; len = fileStream.Length; Byte[] fileAsByte = new Byte[len]; fileStream.Read(fileAsByte, 0, fileAsByte.Length); same logic for writing too Thanks,

      gauthee

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, you can read all bytes of all files you can access. and you can write these bytes again to any location you can access. Since .NET 2.0 you can do it with File.ReadAllBytes and File.WriteAllBytes, you don't need streams for that. Don't really know what good it all will do for you tho. You probably will not be able to understand the bytes, nor change them in any way that results in a valid new document. And you can't just convert a document by changing its file extension, if that were what you hope for. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


      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