Read Zip-File into MemoryStream and use an included XML-File

Aug 24, 2009 at 7:56 PM

Hi all,

please apologize me for my poor english, I use a translator. Sorry for that...

OK, I would like to open a ZIP-File and read included two XML-Files. But it is not allowed to extract any files to my harddisk, so I must open the ZIP-File and read the needed files step by step into a MemoryStream.

What is the best way to do this?

Can I read the first XML-File into a MemoryStream and then open the file with XDocument.load(MemoryStream...)?
When the Archive is encrypted, how can I find out the entryption-mode (e.g. AES256 or other method)?
Can I change different entries in the XML-File/MemoryStream and save back the changes into ZIP-File without saving about the harddisk (I don't know the count of files)?

I'm very happy when you can answer the above questions.

Thanks a lot for your support.


Aug 24, 2009 at 8:07 PM

use ZipEntry.OpenReader to open a stream with the extracted entry.   This is often what you want, when extracting into memory.

You can also extract into an existing stream (like a MemoryStream that you allocate), with the ZipEntry.Extract(Stream) method. 

These methods are documented in the helpfile, and there is example code showing you how to do it.

When the ZipEntry is encrypted, the property ZipEntry.Encryption is set.  Examine it before extracting to learn the encryption method.

You can change the XML content, and then add it back into the zip archive.  Use the UpdateEntry() method to do this. 

Spend some time looking at the documentation, it is very helpful.

Eventually you will want to save the zip archive.  You don't need to save to a filesystem file, but you will want to save it *somewhere*.



Aug 25, 2009 at 10:15 PM

Hello Cheeso,

thank you very much for your information. I would take a look into the documentation, I hope to find all needed information.
I'm also happy that I can read the entries of zip-file into a memorystream, this is the solution for the restriction that it is not allowed to save any files.

Thanks a lot.