none
Zipping files and folders RRS feed

  • Question

  • Hello, I am trying to zip 2 folders and one file in one .zip file but i can not, i have tried with ZipFile and its not working, well of course it can be me that i may have done a mistake but I have checked  so many times the code and I do not see a mistake. I need some help, if someone can probably give me an example of zipping files and folders and explain me what is going on i'd really appreciate it. Im so confused. Thank you for your time.
    Friday, July 13, 2018 11:16 AM

Answers

  • Just loop through the files in the folder and add each one with CreateEntry using a relative path name as per the documentation:

    "When you create a new entry, the file is compressed and added to the zip package. The CreateEntry method enables you to specify a directory hierarchy when adding the entry. You include the relative path of the new entry within the zip package. For example, creating a new entry with a relative path of AddedFolder\NewFile.txt creates a compressed text file in a directory named AddedFolder. "


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by TheodosisXx Saturday, July 14, 2018 1:21 PM
    Saturday, July 14, 2018 12:54 PM
    Moderator

All replies

  • Have you tried using ZipArchive instead?  Did you read through the documentation and look at the examples?

    Give that a try, if you still have trouble, post back with the code you are using and indicate which line (or lines) are failing and show any error messages or explain how the result is not what you want.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, July 13, 2018 12:30 PM
    Moderator
  • Sorry I did not mention that, I have also tried with ZipArchive and to be more specific with ZipArchive.CreateEntry.

    The problem is that with this code I can only zip a specified file, but I need to zip a folder with couple of files and subfolders in it. 


    Saturday, July 14, 2018 9:23 AM
  • Just loop through the files in the folder and add each one with CreateEntry using a relative path name as per the documentation:

    "When you create a new entry, the file is compressed and added to the zip package. The CreateEntry method enables you to specify a directory hierarchy when adding the entry. You include the relative path of the new entry within the zip package. For example, creating a new entry with a relative path of AddedFolder\NewFile.txt creates a compressed text file in a directory named AddedFolder. "


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by TheodosisXx Saturday, July 14, 2018 1:21 PM
    Saturday, July 14, 2018 12:54 PM
    Moderator
  • Thank you very much!

    Saturday, July 14, 2018 1:21 PM