Append in ZipLibrary

3 posts, 1 answers
  1. Adrian
    Adrian avatar
    3 posts
    Member since:
    Jul 2011

    Posted 05 Jan 2012 Link to this post

    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. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 10 Jan 2012 Link to this post

    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 >>

  3. Adrian
    Adrian avatar
    3 posts
    Member since:
    Jul 2011

    Posted 10 Jan 2012 Link to this post

    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

Back to Top