This is a migrated thread and some comments may be shown as answers.

Append in ZipLibrary

2 Answers 66 Views
ZipLibrary
This is a migrated thread and some comments may be shown as answers.
Adrian
Top achievements
Rank 1
Adrian asked on 05 Jan 2012, 11:07 AM

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.

2 Answers, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 10 Jan 2012, 01:09 PM
Hello Adrian,

Unfortunately, we haven't implemented this functionality "out of the box" yet and the "temporary zip" approach is the only one possible currently. We created a feature request in our PITS where you can vote for it, this way increasing its development priority. Thank you for your cooperation.

All the best,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Adrian
Top achievements
Rank 1
answered on 10 Jan 2012, 03:17 PM

Hello Petar, 

Thank you for your answer. I will do as you suggest and use the "temporary" approach.

Keep up the good work and I'm looking forward what kind of improvement will come with this still new Zip Library.

Best Regards

Adrian

Tags
ZipLibrary
Asked by
Adrian
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Adrian
Top achievements
Rank 1
Share this question
or