[英]Download multiple csv files in one zip folder in ASP .Net
I want to add two CSV file in one ZIP file.我想在一个 ZIP 文件中添加两个 CSV 文件。 and download in ASP Net at Clint side.
并在 Clint 端的 ASP Net 中下载。 I am using Data set to merge both data.table record in one data set and need to download at button click.
我正在使用数据集将 data.table 记录合并到一个数据集中,需要在单击按钮时下载。 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" });
}
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.