I want to add two CSV file in one ZIP file. and download in ASP Net at Clint side. I am using Data set to merge both data.table record in one data set and need to download at button click. I am not sure this is good approach or not but, I am getting error on "Archive". I have added
using System.IO;
using System.IO.Compression;
But still Is there any another way to do same. Please guide me
Code:
protected void btnGenerate_Click(object sender, EventArgs e)
{
DataSet ds = getDataCSV();
DataTable dt = ds.Tables[0];
string csv = string.Empty;
foreach (DataRow row in dt.Rows)
{
foreach (DataColumn column in dt.Columns)
{
csv += row[column.ColumnName].ToString().Replace(",", ";") + ',';
}
csv += "\r\n";
}
DataTable dt1 = ds.Tables[1];
string csv1 = string.Empty;
foreach (DataRow row in dt1.Rows)
{
foreach (DataColumn column in dt1.Columns)
{
csv1 += row[column.ColumnName].ToString().Replace(",", ";") + ',';
}
csv1 += "\r\n";
}
using (FileStream zipFile = File.Open("compressed_files.zip", FileMode.Create))
{
using (FileStream source1 = File.Open(csv, FileMode.Open, FileAccess.Read))
{
using (FileStream source2 = File.Open(csv1, FileMode.Open, FileAccess.Read))
{
using (var archive = new Archive())
{
// Add files to the archive
archive.CreateEntry(csv, source1);
archive.CreateEntry(csv1, source2);
archive.Save(zipFile, new ArchiveSaveOptions() { Encoding = Encoding.ASCII, ArchiveComment = "two files are compressed in this archive" });
}
}
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.