如何将crystal report转换为.pdf而不替换以前的.pdf文件?

时间:2012-01-13 02:22:06

标签: c# crystal-reports

如何将水晶报表转换为.pdf而不替换以前的.pdf文件?我确实把“小时,分钟,秒”放了,但它仍然取代了前一个。感谢。

//String reportDate = dt.Year.ToString() + dt.Month.ToString().PadLeft(2, '0') + dt.Day.ToString().PadLeft(2, '0');
String reportPrefix = dt.Year.ToString() + dt.Month.ToString().PadLeft(2, '0') + dt.Day.ToString().PadLeft(2, '0') + dt.Hour.ToString().PadLeft(2, '0') + dt.Minute.ToString().PadLeft(2, '0') + dt.Second.ToString().PadLeft(2, '0') + dt.Millisecond.ToString();
String report = Report + "BillingReport-" + reportPrefix + ".pdf";
crRpt.ExportToDisk(ExportFormatType.PortableDocFormat, report);
Console.WriteLine("" + report + " " + DateTime.Now.ToLongTimeString());

1 个答案:

答案 0 :(得分:0)

您可以使用GUID或DateTime.Now中的Ticks。

或者,如果先前找到了文件,则可以添加索引:

        String reportPrefix = Report + "BillingReport-" + dt.Year.ToString() + dt.Month.ToString().PadLeft(2, '0') + dt.Day.ToString().PadLeft(2, '0') + dt.Hour.ToString().PadLeft(2, '0') + dt.Minute.ToString().PadLeft(2, '0') + dt.Second.ToString().PadLeft(2, '0') + dt.Millisecond.ToString();
        String report;

        bool fDone = false;
        int wIndex = 0;

        // Cycle looking for the first file that doesn't exist
        do while (!fDone) {
            report = reportPrefix;
            // Include the index once we have checked the base file name
            if (wIndex > 0)
            {
                report += wIndex.ToString();
            }
            report += ".pdf";

            if (System.IO.File.Exists(report))
            {
                // If the file exists, increment the index and keep looking
                wIndex++;
            } else {
                // Otherwise, we are done
                fDone = true;
            }
        }