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.