Saving Stream object
-
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."
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)
-
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."
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]