Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET preserve directory structure

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #19338 |

    Is there a way to preserve the directory structure when zipping the files.

    Imported from legacy forums. Posted by Shane (had 2025 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Qex,

    There sure is a way. You could simply instantiate your source DiskFolder and call its .CopyTo method to copy the folder itself and all of its content into the zip archive.

    If, you do not want your source folder to be included and want to only zip up the files within that folder and all of the subfolders and their contents, use the following procedure:

    DiskFolder source = new DiskFolder(@”D:\stuff2zip\”);

    DiskFile target = new DiskFile(@”D:\destination\myStuff.zip”);

    ZipArchive myZip = new ZipArchive(target);

    myZip.BeginUpdate();

    source.CopyFilesTo(myZip,false,true);

    foreach( Xceed.FileSystem.AbstractFolder f in source.GetFolders(false) )
    {
    f.CopyTo(myZip,true);
    }

    myZip.EndUpdate();

    Cheers!

    – PL out

    Imported from legacy forums. Posted by PL (had 3106 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.