Writing from a Stream to a File

R

Rasika

I have zip file called "PPC_DATA.zip" that contains four
jpg images. Using the code below I can get a ZipEntry,
which can be converted into a Stream by using
zFile.GetInputStream(e). I want to know how to write the
Stream I get in this way into files.


I have included the code below, but converting the Stream
(from 'zFile.GetInputStream(e);') into a file named
('e.Name;') is confusign me...

===========

ZipFile zFile = new ZipFile(@"c:\My
Documents\PPC_DATA.zip");

foreach (ZipEntry e in zFile) {
FileStream fs = new FileStream(@"C:\My
Documents\" + e.Name, FileMode.Create);
BinaryWriter w = new BinaryWriter(fs);

//zFile.GetInputStream(e);

}
 
J

Jon Skeet

Rasika said:
I have zip file called "PPC_DATA.zip" that contains four
jpg images. Using the code below I can get a ZipEntry,
which can be converted into a Stream by using
zFile.GetInputStream(e). I want to know how to write the
Stream I get in this way into files.


I have included the code below, but converting the Stream
(from 'zFile.GetInputStream(e);') into a file named
('e.Name;') is confusign me...

Have a look at the bottom example in
http://www.yoda.arachsys.com/csharp/readbinary.html

That happens to write to a memory stream instead of a file stream, but
the "read a block, write it" loop is the same as what you need.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top