I'm trying to build a zip file that contains other zip files, the internal zip files contain XML files serialized from data model objects. I need to keep them in specific groups hence the zip of zips.
This is being done server side by microservices, and returned via a web service controller to the user.
The problem is that I get the following error can anybody tell me why?
An unhandled exception occurred while processing the request.
ObjectDisposedException: Cannot access a closed Stream.
System.IO.MemoryStream.Read(byte[] buffer, int offset, int count)
Thanks
Madaxe
This is being done server side by microservices, and returned via a web service controller to the user.
The problem is that I get the following error can anybody tell me why?
An unhandled exception occurred while processing the request.
ObjectDisposedException: Cannot access a closed Stream.
System.IO.MemoryStream.Read(byte[] buffer, int offset, int count)
Thanks
Madaxe
Building Zip Files In Memory:
private MemoryStream BuildRootZip()
{
MemoryStream ReturnMemoryStream = new MemoryStream();
using (ReturnMemoryStream)
{
using (var archive = new ZipArchive(ReturnMemoryStream, ZipArchiveMode.Create, true))
{
int ZipIndex = 1;
foreach (XMLMachiningModel XMLMachiningModel in this._XMLMachiningModels)
{
string ZipFileName = string.Concat("ReaJetXMLPackage_", ZipIndex, ".zip");
byte[] ZipFile = this.BuildSubZip(XMLMachiningModel, ZipFileName);
var zipArchiveEntry = archive.CreateEntry(ZipFileName, CompressionLevel.Fastest);
using (var zipStream = zipArchiveEntry.Open()) zipStream.Write(ZipFile, 0, ZipFile.Length);
ZipIndex++;
}
}
ReturnMemoryStream.Seek(0, SeekOrigin.Begin);
}
return ReturnMemoryStream;
}
private byte[] BuildSubZip(XMLMachiningModel XMLMachiningModel, string ZipFileName)
{
byte[] ReturnBytes;
using (var ZipMemoryStream = new MemoryStream())
{
using (var archive = new ZipArchive(ZipMemoryStream, ZipArchiveMode.Create, true))
{
var zipArchiveEntry = archive.CreateEntry(ZipFileName, CompressionLevel.Fastest);
byte[] XMLFile = Encoding.ASCII.GetBytes(XMLParsing.SerializeObject(XMLMachiningModel.ReaJetSideBase));
using (var zipStream = zipArchiveEntry.Open()) zipStream.Write(XMLFile, 0, XMLFile.Length);
}
ZipMemoryStream.Position = 0;
ReturnBytes = new byte[ZipMemoryStream.Length];
ZipMemoryStream.Read(ReturnBytes, 0, ReturnBytes.Length);
}
return ReturnBytes;
}
Last edited: