I am trying to download zip files on the basis of multiple selection meaning the user selects documents and presses the download files button and then the zip file is generated.
Everything is working correctly. My zip files are also being downloaded. But sometimes when I press download button again and again , it give me the below error. I have noticed that this error is not generated when I download any new files. But when I download those files which I have already downloaded mutiiple times, then this error is generated
An item with the same key has already been added.
Note this error is generated very rare. And I cant seem to figure out why after multiple google searches. I am posting my code below. Can anyone help me?
using (ZipFile zip = new ZipFile())
{
foreach (DataRow row in dt.Rows)
{
//some code
zip.AddFile(filePath, "files"); //here the error is
generated
}
Response.Clear();
//Response.AddHeader("Content-Disposition", "attachment; filename=DownloadedFile.zip");
Response.ContentType = "application/zip";
zip.Save(Response.OutputStream);
Response.End();