Answered by:
Create zip file of part of folder

Question
-
Hello,
I need to create a zip file from a folder. I found the code for that and I noticed that it creates the file for all the directories in the folder. My question is if it's possible to create the zip file for only selected directories in the folder??
(for exmple if the folder contains 4 images and 2 text files, the zip file will inclued only 3 of the images and 1 text file, that I will select manually from the code)Monday, January 29, 2018 9:25 PM
Answers
-
For example :
using (ZipArchive newZip = ZipFile.Open(@"E:\testzip.zip", ZipArchiveMode.Create)) { newZip.CreateEntryFromFile(@"E:\file1.txt", "file1.txt", CompressionLevel.Fastest); newZip.CreateEntryFromFile(@"E:\file2.txt", "file2.txt", CompressionLevel.Fastest); // ... }
- Proposed as answer by Zhanglong WuMicrosoft contingent staff Friday, February 2, 2018 9:30 AM
- Marked as answer by Roy Jiny Friday, March 9, 2018 10:42 AM
Monday, January 29, 2018 9:59 PM
All replies
-
For example :
using (ZipArchive newZip = ZipFile.Open(@"E:\testzip.zip", ZipArchiveMode.Create)) { newZip.CreateEntryFromFile(@"E:\file1.txt", "file1.txt", CompressionLevel.Fastest); newZip.CreateEntryFromFile(@"E:\file2.txt", "file2.txt", CompressionLevel.Fastest); // ... }
- Proposed as answer by Zhanglong WuMicrosoft contingent staff Friday, February 2, 2018 9:30 AM
- Marked as answer by Roy Jiny Friday, March 9, 2018 10:42 AM
Monday, January 29, 2018 9:59 PM -
For example :
using (ZipArchive newZip = ZipFile.Open(@"E:\testzip.zip", ZipArchiveMode.Create)) { newZip.CreateEntryFromFile(@"E:\file1.txt", "file1.txt", CompressionLevel.Fastest); newZip.CreateEntryFromFile(@"E:\file2.txt", "file2.txt", CompressionLevel.Fastest); // ... }
Tuesday, January 30, 2018 12:56 PM -
Does it also create the "testzip.zip" file or it should be created manually at first?
It creates it.Tuesday, January 30, 2018 12:58 PM -
Does it also create the "testzip.zip" file or it should be created manually at first? It creates it.
OK thanks I will try it!
Tuesday, January 30, 2018 1:03 PM -
For example :
using (ZipArchive newZip = ZipFile.Open(@"E:\testzip.zip", ZipArchiveMode.Create)) { newZip.CreateEntryFromFile(@"E:\file1.txt", "file1.txt", CompressionLevel.Fastest); newZip.CreateEntryFromFile(@"E:\file2.txt", "file2.txt", CompressionLevel.Fastest); // ... }
Does it also create the "testzip.zip" file or it should be created manually at first?
How should it be done with folders?Tuesday, January 30, 2018 8:40 PM -
It works well with files for me, but when I try to add a folder it doesnt work...
How should it be done with folders?There are workarounds, like CreateEntryFromFolder (not tested)
- Proposed as answer by Zhanglong WuMicrosoft contingent staff Friday, February 2, 2018 9:30 AM
Tuesday, January 30, 2018 9:14 PM