Have only one image that is the byte[] bytes and I am trying to compress to Zip for the user to download as far I can see the byte array is saved in the MemoryStream.
The probleam is when I trie to read the buffer of MemoryStream to ImagesAux this way zippedMemoryStream.Read(ImagesAux, 0, 1000000);
doesn't work but ImagesAux = zippedMemoryStream.ToArray();
this way allready works ... then stream.Write(ImagesAux, 0, ImagesAux.Length);
as to pass the ZipFile to SaveFileDialog doesn't work either get the size of ImagesAux but not the content from what I saw, the ZipFile is created but gives a error of Format not supported in ALZip, can someone point what I'm doing wrong??
MemoryStream zippedMemoryStream = new MemoryStream();
ZipOutputStream zipOutputStream;
zipOutputStream = new ZipOutputStream(zippedMemoryStream, 1000000);
zipOutputStream.SetLevel(0);
zipOutputStream.UseZip64 = UseZip64.On;
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
ZipEntry entry = new ZipEntry(ZipEntry.CleanName(ImageNameServer));//ImageNameServer
entry.DateTime = DateTime.Now;
entry.Comment = "Teste";
entry.ZipFileIndex = 1;
entry.Size = bytes.Length;
zipOutputStream.PutNextEntry(entry);
zipOutputStream.Write(bytes, 0, bytes.Length);
var something = zipOutputStream.GetType();
var lvl = zipOutputStream.GetLevel();
//zippedMemoryStream.Write(bytes, 0, bytes.Length);
zippedMemoryStream.Read(buffer, 0, bytes.Length);
MemoryStream auxxpto = new MemoryStream();
zippedMemoryStream.WriteTo(auxxpto);
buffer = auxxpto.ToArray();
private void DataSetDownload(object sender, RoutedEventArgs e)
{
var dialog = new SaveFileDialog();
dialog.Filter = "Zip Files (*.zip)|*.zip";
dialog.DefaultExt = "zip";
dialog.DefaultFileName = "DataSet.zip";
bool? fileSelected = dialog.ShowDialog();
byte[] ImagesAux = new byte[1000000];
if (fileSelected == true)
{
var value = zippedMemoryStream.CanWrite;
var read = zippedMemoryStream.CanRead;
zippedMemoryStream.Read(ImagesAux, 0, 1000000);
ImagesAux = zippedMemoryStream.ToArray();
//ZippedFile.Read(ImagesAux, 0, ImagesAux.Length);
//ImagesAux = zippedMemoryStream.ToArray();
zipOutputStream.Finish();
zipOutputStream.Close();
using (Stream stream = dialog.OpenFile())
{
stream.Write(ImagesAux, 0, ImagesAux.Length);
//stream = zippedMemoryStream.ToArray();
//stream.Flush();
//stream.Close();
}
}
}