User-1765822410 posted
I am trying to export data in a zip file but not creating in server instead writing the bytes.
Below is the code, i have written. There is no exception, but when i open the file from open save file dialog, it says the file is corrupted.
ZipOutputStream objZipOutputStream = null;
ZipEntry objZipEntry = null;
MemoryStream objStream = new MemoryStream();
byte[] data = null;
int streamLength = 0;
try
{
objZipOutputStream = new ZipOutputStream(objStream);
for (int i = 0; i < objKMZs.Count; i++)
{
data = objKMZs[i] as byte[];
objZipEntry = new ZipEntry("KMZ" + i + ".KMZ");
objZipEntry.Size = data.Length;
objZipOutputStream.PutNextEntry(objZipEntry);
objZipOutputStream.Write(data, 0, data.Length);
}
streamLength =int.Parse(objZipOutputStream.Length.ToString());
if (objZipOutputStream != null)
{
objZipOutputStream.Finish();
}
}
catch
{
if (objZipOutputStream != null)
{
objZipOutputStream.Finish();
}
throw;
}
data = new byte[streamLength];
objStream.Read(data, 0, streamLength);
objZipOutputStream.Dispose();
Response.Expires = -1;
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-disposition", "attachment;filename=data.zip");
Response.BinaryWrite(data);
Response.End();
Response.Flush();
Response.Clear();