2012-01-13 48 views
0

任何想法如何將水晶報告轉換爲.pdf而無需替換以前的.pdf文件?我確實放了「小時,分鐘,秒」,但它仍然取代了前一個。謝謝。如何將水晶報告轉換爲.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()); 
+0

您的文件命名方案應取決於您計劃一旦被生成訪問文件的方式。如果這些只是臨時文件的文件名將立即呈現給用戶,那麼compentent_tech的解決方案應該是有用的。或者,如果文件名將永遠需要人工發現或發現,那麼你應該考慮一個更合乎邏輯的命名方案(用戶知道或可能猜到的東西)。 – 2012-01-13 02:41:36

回答

0

您可以使用DateTime.Now中的GUID或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; 
      } 
     } 
+0

我已經使用「static DateTime dt = DateTime.Now;」我並不熟悉GUID,但會嘗試搜索它..如果你有任何代碼的例子,將不勝感激。謝謝 – srahifah 2012-01-13 02:41:09

+0

謝謝,讓我先試試。 :) – srahifah 2012-01-13 02:43:16

+0

competent_tech,謝謝..但仍然有同樣的問題,如果我重新運行我的應用程序。不知道它爲什麼會發生。它不應該被替換,因爲該文件將在第n秒鐘不同。 – srahifah 2012-01-13 04:20:01