how to zip the file using ionic

how to zip the file using ionic

  private string WriteResponseInZip()

DataSet ResultDataSet= new DataSet();
DataTable customers = myDataset.Tables.Add("Customers");




.Rows.Add("Chris", "25");

//Prefixing the filename for download data.

var fileName = “TestFile” + “_” + Guid.NewGuid();
var srcDirectory = “C:Test appstestfinal” + fileName + “\”;
var destinDirectory = “C:Test appstestfinal1”;
var srcFile = srcDirectory + fileName + “.txt”;  // Put the source file name
var desFile = destinDirectory + fileName + “.zip”;// to contanin destination file path

//creating a source directory to store the file.

//Writing response to src txt file
File.WriteAllText(srcFile, JsonConvert.SerializeObject(ResultDataSet, Formatting.None)); put data in any dataset and pass here ex. ResultDataset

//Creating Password protected zip file
using (var zip = new ZipFile())
zip.AddFile(srcFile, “.”);// “.” is passed to provide the compressed file at root level.

//Zompressing the src directory
//ZipFile.CreateFromDirectory(srcDirectory, desFile);

//Deleteing Source file/directory as zip file is created
Directory.Delete(srcDirectory, true);
return fileName;

1). For performing the above operation. first download the file from Nuget Package mangaer in Solution Explorer. 
and done the above operation , you will get zip folder download with content.

For reference : how to zip the file using ionic library


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.