导出PDF错误,已添加具有相同键的项目

时间:2015-07-23 18:07:28

标签: c# asp.net database dictionary

我正在尝试从数据库导出pdf,但我有这个问题

  

已添加具有相同键的项目

在最后一行 - zip.AddFile(str, "");

那么如何解决这个问题呢?以下是代码:

public static void generateRespondentReport(string startDate, string endDate)
{
    List<string> inpatientFileList = generateRespondentReportByQuestionSet(1, startDate, endDate);
    List<string> outpatientFileList = generateRespondentReportByQuestionSet(2, startDate, endDate);
    List<string> visitorFileList = generateRespondentReportByQuestionSet(3, startDate, endDate);

    // timestamp           
    DateTime now = DateTime.Now;
    string FileName = "RespondentReport_" + now.Day + now.ToString("MMM") + now.Year + "_" + string.Format("{0:hh-mm-sstt}", now) + ".zip";
    System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
    response.ClearContent();
    response.Clear();
    response.ContentType = "application/zip";
    response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");

    // add into zipfile
    ZipFile zip = new ZipFile();
    foreach (string str in inpatientFileList)
    {
        zip.AddFile(str, "");
    }
    foreach (string str in outpatientFileList)
    {
        zip.AddFile(str, "");
    }
    foreach (string str in visitorFileList)
    {
        zip.AddFile(str, "");
    }

1 个答案:

答案 0 :(得分:0)

在添加文件之前,首先检查zip ...

中是否存在该文件
        foreach (string str in <X>)
        {
            var nameCount = zip.Count(entry => entry.FileName == str);
            if (nameCount>0)
            {
                zip.AddFile(str + string.Format("({0})",nameCount), "");
            }
            else
            {
                zip.AddFile(str, "");
            }
        }