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 |
You need to create an archive from a list of files.
Use [RadZipLibrary]({%slug radziplibrary-overview%}) to create and export the archive.
{{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}}