or
Hi there,
I've got a small application and now stuck in the task "Appending Files in Zip".
As far as it looks the ZipPackage only allow to Read or Write. Not both.
The Codeblock with the routine
ZipPackage zipPackage; if (File.Exists(appPath + @"\" + currentMonthZip)) { Stream stream = File.OpenRead(appPath + @"\" + currentMonthZip); zipPackage = ZipPackage.Open(stream, FileAccess.ReadWrite); } else{ Stream stream = File.Create(appPath + @"\" + currentMonthZip); zipPackage = ZipPackage.Create(stream); } foreach (string folderName in logFoldernames) { string[] listLogs = Directory.GetFiles(appPath + @"\" + folderName); foreach (string listLogName in listLogs) { zipPackage.Add(listLogName, folderName + @"\" + Path.GetFileName(listLogName)); } Directory.Delete(appPath + @"\" + folderName); }I'm aware that maybe the problem lays here but change the FileAccess or FileMOde ends in exceptions (Stream not for Read/Write)
Stream stream = File.OpenRead(appPath + @"\" + currentMonthZip); zipPackage = ZipPackage.Open(stream, FileAccess.ReadWrite); So what's the suggested approach to open an existing Zip and just attach some new Files in it?
Do I really have to create a temporary zip with old and new content and afterwards delete the old zip and rename the new to the proper name?
Thanks for any help.
public static void ZipStream(Stream oInStream, string sFileName, Stream oZipStream) { ZipPackage oZipPackage = ZipPackage.Create(oZipStream); oZipPackage.AddStream(sFileName, oInStream); } public static Stream UnzipStream(Stream oZipStream, int iIndex = 0) //this is incorrect; returns zipped stream { ZipPackage oZipPackage = ZipPackage.Open(oZipStream, FileAccess.Read); return oZipPackage.ZipPackageEntries[iIndex].OpenInputStream(); }
request.BeginGetResponse(result => { var response = request.EndGetResponse(result) as HttpWebResponse; try { // StreamResourceInfo info = new StreamResourceInfo(response.GetResponseStream(), null); //StreamResourceInfo zip = Application.GetResourceStream(info, new Uri("datos", UriKind.RelativeOrAbsolute)); Stream info = response.GetResponseStream(); if (ZipPackage.IsZipFile(info)) { using (ZipPackage zipPackage = ZipPackage.Open(info, FileAccess.Read)) { ZipPackageEntry zip = zipPackage.ZipPackageEntries[0]; using (Stream responseStream = zip.OpenInputStream()) { using (StreamReader reader = new StreamReader(responseStream)) { string texto = reader.ReadToEnd(); lista = JsonConvert.DeserializeObject<List<Reportes>>(texto); dis.BeginInvoke(new AddtoLista(LlenarLista), lista); reader.Close(); responseStream.Close(); } } } } } catch (Exception ex) { throw ex; } }, null);