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 Stream object

Saving Stream object

Scheduled Pinned Locked Moved C#
question
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.
  • D Offline
    D Offline
    Den2Fly
    wrote on last edited by
    #1

    Hello all, I wana ask a simple question! How a Stream object can be saved into the disk?!! Thank u :) --- "Art happens when you least expect it."

    M H 2 Replies Last reply
    0
    • D Den2Fly

      Hello all, I wana ask a simple question! How a Stream object can be saved into the disk?!! Thank u :) --- "Art happens when you least expect it."

      M Offline
      M Offline
      matthias s 0
      wrote on last edited by
      #2

      Hi, Stream is an abstract base class. You could use it's deriative, the FileStream for easy writing to a file using the BinaryFormatter class. HTH, Matthias

      If eell I ,nust draw to your atenttion to het fakt that I can splel perfrectly well - i;ts my typeying that sukcs. (Lounge/David Wulff)

      www.emvoid.de

      1 Reply Last reply
      0
      • D Den2Fly

        Hello all, I wana ask a simple question! How a Stream object can be saved into the disk?!! Thank u :) --- "Art happens when you least expect it."

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        It greatly depends on what the stream is. More information would be helpful. The snippet below - depending on whether or not the stream supports seeking - would work for many cases (but certainly not all, like with a NetworkStream - but not limited to it):

        if (stream.CanSeek<)
        {
        stream.Seek(0, SeekOrigin.Begin);
        using (FileStream file = new FileStream("file.dat", FileMode.Create,
        FileAccess.Write, FileShare.Read))
        {
        int read = 0;
        byte[] buffer = new byte[4096];
        while ((read = stream.Read(buffer, 0, 4096)) > 0)
        {
        file.Write(buffer, 0, read);
        }
        file.Flush();
        }
        }

        This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles]

        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