By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

How to save stream data to file using filestream?

P: n/a
Hi,

I have function which return instance of object Stream and i want that stream object to save to file.
How can i do that?

my code is:

Stream s = MyGetStream();

my question is what i must to do to save stream object s to file ?
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Try reading this for an insight into working with streams and the file
system objects.

http://www.codeguru.com/Csharp/Cshar...cle.php/c4215/

Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"terrorix" <te******@centrum.sk> wrote in message
news:eL**************@TK2MSFTNGP10.phx.gbl...
Hi,

I have function which return instance of object Stream and i want that stream object to save to file. How can i do that?

my code is:

Stream s = MyGetStream();

my question is what i must to do to save stream object s to file ?

Nov 18 '05 #2

P: n/a
John Timney (Microsoft MVP) wrote:
Try reading this for an insight into working with streams and the file
system objects.

http://www.codeguru.com/Csharp/Cshar...cle.php/c4215/

Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"terrorix" <te******@centrum.sk> wrote in message
news:eL**************@TK2MSFTNGP10.phx.gbl...
Hi,

I have function which return instance of object Stream and i want that

stream object to save to file.
How can i do that?

my code is:

Stream s = MyGetStream();

my question is what i must to do to save stream object s to file ?


there is only article "Inside C#, Second Edition: File I/O with Streams - Part 1" and other parts are not there. Gives me error "Article not found"
Nov 18 '05 #3

P: n/a
terrorix wrote:
Hi,

I have function which return instance of object Stream and i want
that stream object to save to file. How can i do that?

my code is:

Stream s = MyGetStream();

my question is what i must to do to save stream object s to file ?


The quintessential stream copying method:

public void Copy(Stream source, Stream target) {
byte[] buffer = new byte[0x10000];
int bytes;
try {
while ((bytes = source.Read(buffer, 0, buffer.Length)) > 0) {
target.Write(buffer, 0, bytes);
}
}
finally {
target.Flush();
// Or target.Close(); if you're done here already.
}
}

If you use a FileStream instance as "target", you'll get what you want.

Cheers,
--
Joerg Jooss
jo*********@gmx.net
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.