Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Exceed Zip library for .NET issue with preserving path of folders

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

    Hello ,
     
    I have two files located in folder structure as follows
    1) C:\Abc\Def\F1.Doc
    2) C:\Abc\Hij\F2.Doc

    I want to create ZIp file which will contain both F1.doc and F2.doc, by preseving their folder structure and base path as “C:\Abc”. i.e. when I unzip my file at any location, then it will create F1.Doc in Def folder and F2.Doc in Hij folder and does not create “C:\Abc”.

    This we used to do in earlier version of xCeed by giving below property
    XceedZip1.BasePath = “C:\Abc”
    XceedZip1.PreservePaths = True

    I am using Xceed Zip library for .NET now. Can any body provide me sample code in .NET for the same or Property names?

    Imported from legacy forums. Posted by chetan (had 3048 views)

    User (Old forums)
    Member
    Post count: 23064

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Xceed.Zip;
    using Xceed.FileSystem;

    namespace _25975_PreservZIPPath
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                ZipArchive myZip = new ZipArchive(new DiskFile(@”D:\ZipTest\AllFiles.zip”));

                myZip.BeginUpdate();

                foreach (DiskFolder df in new DiskFolder(@”D:\ZipTest\”).GetFolders(false))
                {
                    df.CopyTo(myZip, true);
                }

                myZip.EndUpdate();
            }
        }
    }

    In AllFiles.zip, I have exactly

    1) \Abc\Def\F1.Doc
    2) \Abc\Hij\F2.Doc

    since I have that folder structure + two Word documents.

    Best regards,

    Imported from legacy forums. Posted by Ghislain (had 953 views)

    User (Old forums)
    Member
    Post count: 23064

    I have the similar issue. How to preserve the directory hierarchy, just by taking the seperate files from different directories. ie a:\b\c\d.txt and a:\b\e\f.txt

    and when i unzip, it should have c\d.txt and e\f.txt  ie rather than using entire folder contents, I need to deal with single files in a directory?

     

     

    Imported from legacy forums. Posted by naresh (had 335 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Naresh,

    for your particuliar situation, assuming you have a C: drive with a writable \temp folder, the simplest answer is:

    namespace _26165_PreservZIPPath
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                ZipArchive myZip = new ZipArchive(new DiskFile(@”C:\Temp\AllMyFiles.zip”));

                myZip.BeginUpdate();

                foreach (DiskFolder df in new DiskFolder(@”A:\B\”).GetFolders(false))
                {
                    df.CopyTo(myZip, true);
                }

                myZip.EndUpdate();
            }
        }
    }

    Of course, for more flexibility, you could get the user input, (i.e. the starting point of the hyerarchy of the folders to be zipped), in a textbox, and the destination in another textbox, minimally.  And this would have to be activated by a click of a button, of course, splitting the code above so you get the InitiazeComponent() out of event handler code., There are tons of ways to improve the basic solution.  

    Best regards

    Imported from legacy forums. Posted by Ghislain (had 1246 views)

    User (Old forums)
    Member
    Post count: 23064

    I have a similar problem where I want to retain the folder structure, but only want to zip certain files in each folder (rather than all the files).  The CopyTo method doesn’t allow for a filter.  How can I zip certain files and still retain the folder structure?

    Imported from legacy forums. Posted by Brad (had 1663 views)

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