Hello. Tell me, please, how can I archive a separate file, video or image to the archive on wpf?
Closed due to the fact that the issue is too common for the participants Eugene Krivenja , Cheg , αλεχολυτ , rdorn , HamSter Aug 3, '17 at 6:56 pm .
Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .
3 answers
Use DotNetZip
Usage example: archive creation
using (ZipFile zip = new ZipFile()) { // add this map file into the "images" directory in the zip archive zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images"); // add the report into a different directory in the archive zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files"); zip.AddFile("ReadMe.txt"); zip.Save("MyZipFile.zip"); } - Thanks for the help - user222335
You need a toolkit from System.IO.Compression .
An example of creating the archive C:\result.zip , containing the file C:\data.txt :
using (var fileStream = new FileStream(@"C:\result.zip", FileMode.Create)) using (var archive = new ZipArchive(fileStream, ZipArchiveMode.Create)) { archive.CreateEntryFromFile(@"C:\data.txt", "data.txt"); } To use the CreateEntryFromFile extension method, you must connect the System.IO.Compression.FileSystem assembly.
I recommend to study the following manual: https://msdn.microsoft.com/ru-ru/library/ms404280(v=vs.110).aspx
- Thanks for the help - user222335
Archiving is a very broad concept. If we are talking about creating an archive file in one of the common formats, see the answers of users.
If you just need to compress the file in order to reduce the volume, and store it at least on the file system, even in RAM, the more lightweight GZipStream will do .
- Thanks for the help, first you need to compress the file, and then upload it to the archive - user222335
ZipFileandZipArchive- Andrey NOP