Welcome, Guest
Username: Password: Remember me
This forum is the place to discuss issues related to ReportPro, Xs2Ado, Vo2Ado, bBrowser and other 3rd party products
  • Page:
  • 1

TOPIC:

How to add disk in zip using DotNetZip 31 Mar 2022 12:47 #22063

  • ic2
  • ic2's Avatar
  • Topic Author


  • Posts: 1555
  • This is probably something Fabrice can answer? (as FabZip is based on DotNetZip).

    I use DotNetZip for creating zips. It has many option but I couldn't find if it is possible to store the disk where the file is located, in the archive. E.g. like the Absolute mode in 7-Zip. As far as I can see I can only do this:
    zip.AddFile(cFileFull, cPath);

    When cFileFull is e.g. "c:\temp\SomeFile.txt" and cPath = "c:\temp" opening the zipfile shows

    temp

    while I would like to see

    C
    and then, when I click on C

    temp

    This would allow storing the same path/file found on different drives. Is this possible?

    Dick

    Please Log in or Create an account to join the conversation.

    How to add disk in zip using DotNetZip 05 Apr 2022 09:30 #22081

    • Fabrice
    • Fabrice's Avatar


  • Posts: 302
  • Hi Dick,
    If I get you right, your goal is to store the "original" disk (and path may be) in the Zip File ?
    I would think that this is not possible per design : You always store relative's path of file.
    And I think this is good : Imagine zipping a file stored originally on a Y:\ drive, trying to unzip it... when you don't have a Y drive ?

    That said, You (as a developer) can inject some informations within the ZipFile (the container), or per file inside the Zip, in order to keep that info :
    The ZipFile and the ZipEntry classes have a property named Comment. You can store here any information you would find usefull in String format, so... It's up to you ;)

    HTH,
    Fab

    Please Log in or Create an account to join the conversation.

    How to add disk in zip using DotNetZip 05 Apr 2022 09:41 #22084

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3199
  • Hi Dick,
    the zip file format does not defines drives, it allows only to store the drive label.
    On other platforms than Windows (and DOS) there is no drive, only folders.
    So this is not a problem of DotNetZip, but of the zip format.
    And as Fabrice wrote: it would be very risky to restore to the same drive letter: immagine you are saving from a USB drive on one machine and the restore would overwrite a network drive or a local disk on a different machine.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    How to add disk in zip using DotNetZip 05 Apr 2022 13:01 #22086

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1555
  • Hello Wolfgang, Fabrice,

    Thanks for your replies. I think it is a 7-Zip feature, see picture. I select Absolute pathnames and when opening the zip in Explorer it is empty but in 7-Zip you see first the disk and then the directory.

    I think this is better, because now selecting a file with the same name on c:\temp and d:\temp means the latter won't be added in the zip. And you can restore in a different disk. But I also think it would be hard to achieve as it is not standard supported in DotNetZip.



    EDIT: I actually didn't try what would happen if I add the same file(name) residing in the same directory for 2 different disks.

    Turns out that both files are added, with the same name in the same directory. Open each of the files and you see the different content. So I think it's indeed a good idea to check out the comment option, to at least show from which disk the files were.


    Dick
    Attachments:

    Please Log in or Create an account to join the conversation.

    Last edit: by ic2. Reason: Added result of test adding 2 files/different disks

    How to add disk in zip using DotNetZip 07 Apr 2022 17:46 #22117

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1555
  • Hello Fabrice,

    Your reply about using the comment turned out to be an absolutely brilliant workaround. Instead of zip.AddFile(cFileFull, cPath); the code is now:
    var zipEntry=zip.AddFile(cFileFull, cPath);
    zipEntry.Comment=cPath.Substring(0,1);

    In a program like 7-zip you can see the comment, being the drive letter, and this is then the only difference if I add 2 exactly the same files in the same directory.

    Thanks a lot!

    Dick

    Please Log in or Create an account to join the conversation.

    Last edit: by ic2.
    • Page:
    • 1