Extract File To MemoryStream

Sep 1, 2009 at 9:02 PM

I have a text file that was compressed by 7Zip that I want to read from within a program.  I want to put the contents of that text file into a MemoryStream and read it with a StreamReader.  My current code is as follows:

SevenZipExtractor extractor = new SevenZipExtractor("@C:\TestFile.7z");

MemoryStream ms = new MemoryStream();

extractor.ExtractFile(0, ms);

StreamReader sr = new StreamReader(ms);

MessageBox.Show(sr.ReadToEnd());

sr.ReadToEnd() just gives me a blank string.

I can unzip my TestFile.7z file with ExtractArchive, but I do not want to extract it to a file.  I want to get the contents of the file without having to create files (because of possible permission issues).  Can I even do this with the SevenZipExtractor object?

Coordinator
Sep 1, 2009 at 10:42 PM

Maybe that's because

extractor.ExtractFile(0, ms); //Line added here ms.Position = 0; StreamReader sr = new StreamReader(ms); MessageBox.Show(sr.ReadToEnd());

?

Sep 2, 2009 at 3:56 AM
Edited Sep 2, 2009 at 3:57 AM

Wow, I almost want to delete my post because of how dumb that was to miss.  Thanks for the help.