Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 1.55 KB

archive-a-list-of-files.md

File metadata and controls

55 lines (43 loc) · 1.55 KB
title description type page_title slug position tags res_type
Create archive from a list of files
Learn on how you can create an archive from a list of files using ZipLibrary, part of Telerik Document Processing.
how-to
Create archive from a list of files
archive-a-list-of-files
0
zip, archive, files
kb
Product Version Product Author
2020.1.219 RadZipLibrary Dimitar Karamfilov

Description

You need to create an archive from a list of files.

Solution

Use [RadZipLibrary]({%slug radziplibrary-overview%}) to create and export the archive.

C#

{{region kb-archive-a-list-of-files1}} List fileNames = new List();

fileNames.Add("text.txt");
fileNames.Add("text1.txt");
fileNames.Add("text2.txt");

string zipFileName = "Result.zip";

using (Stream stream = File.Open(zipFileName, FileMode.Create))
{
    using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true, entryNameEncoding: null))
    {
        foreach (var file in fileNames)
        {
            using (ZipArchiveEntry entry = archive.CreateEntry(file))
            {
                var entryStream = entry.Open();
                FileStream fs = new FileStream(file, FileMode.Open);
                fs.CopyTo(entryStream);
                entryStream.Flush();

                fs.Close();
                fs.Dispose();
            }
        }
    }
}

{{endregion}}