0

I have been developing an web application with Asp.Net and I'm using SharpZipLib to work with odt files (from Open Office) and in the future docx files (for ms office). I need to open an odt file (like a zip file) change a xml file inside it, zip again and give it to the browser send to my client.

I can do this in file system but it will get a space in my disk temporarily and we don't want it. I would like to do this in memory (with a MemoryStream class), but I don't know how to unzip folders/files in a memory stream with SharpZipLib, change and use it to zip again. Is there any sample about how to do this?

Thank you

Felipe Oriani
  • 37,948
  • 19
  • 131
  • 194

1 Answers1

0

You can use something like

 Stream inputStream = //... File.OpenRead(...);

  //for read file
 ZipInputStream zipInputStream = new ZipInputStream(inputStream));

 //for output 
 MemoryStream memoryStream  = new MemoryStream();



using ( ZipOutputStream zipStream = new ZipOutputStream(memoryStream))
{




          ZipEntry entry = new ZipEntry("...");
          //...

          zipStream.PutNextEntry(entry);
          zipStream.Write(data, 0, data.Length);
          //...


          zipStream.Finish();
          zipStream.Close();

}

Edit ::

You need in general unZip your file, get ZipEntry , change , and write in ZipOutputStream with MemoryStream. Use this article http://www.codeproject.com/KB/cs/Zip_UnZip.aspx

Sergey Gazaryan
  • 1,013
  • 1
  • 9
  • 25