2012-04-25 80 views
-3

我在將水晶報告導出爲pdf時遇到一些問題。我的程序在teleneUdaje.rpt的負載下崩潰,我確信它是正確的名稱。Crystal報告導出崩潰C#

if(txtpath.Text ==「」)拋出新的異常(「Prosímzvoľtecieľovúadresu」);

DataSet dt = new DataSet(); 

    string x = nastavenia.adresa_servera(); 
    string y = nastavenia.nazov_databazy(); 
    string z = nastavenia.ponechat_udaje(); 
    string a = nastavenia.sql_meno(); 
    string b = nastavenia.sql_heslo(); 

    SqlConnection databaza = new SqlConnection(); 
    databaza.ConnectionString = "Data Source=" + x + ";Initial Catalog=" + y + ";Persist Security Info=" + z + ";User ID=" + a + "; password=" + b + ""; 
    da.SelectCommand = new SqlCommand("SELECT * FROM tblTepelneUdaje", databaza); 
    dt.Clear(); 
    da.Fill(dt); 


    System.IO.FileInfo info = new System.IO.FileInfo(txtpath.Text.Trim()); 
    string type = info.Extension; 

    CrystalDecisions.Shared.ExportFormatType tp = CrystalDecisions.Shared.ExportFormatType.Excel; 

    switch (type) 
    { 
     case ".pdf": 
      tp = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; 
      break; 
     case ".doc": 
      tp = CrystalDecisions.Shared.ExportFormatType.WordForWindows; break; 
     case ".rtf": 
      tp = CrystalDecisions.Shared.ExportFormatType.RichText; break; 
     case ".xls": 
      tp = CrystalDecisions.Shared.ExportFormatType.Excel; break; 
     default: MessageBox.Show("Invalid File type you entered"); break; 
    } 

    ReportDocument doc = new ReportDocument(); 
    doc.Load("TeleneUdaje.rpt"); 
    doc.SetDataSource(dt); 
    doc.ExportToDisk(tp, txtpath.Text); 
    MessageBox.Show("Zostava bola úspešne exportovaná"); 

請幫忙。

**編輯

它拋出的Crystal Reports異常報告加載失敗。該文件是可以的,因爲在該程序中,我可以使用報告查看器工具顯示報告。

+2

崩潰怎麼辦?它是否會拋出異常?寫什麼東西到磁盤? – 2012-04-25 21:47:28

+0

@AdamV它拋出水晶報告異常報告加載失敗 – MichalCh 2012-04-25 21:55:01

+0

這聽起來像那個報告有問題。我對Crystal Reports沒有任何經驗,但我會嘗試手動打開它並查看是否在文件中看到任何錯誤。 – 2012-04-26 14:09:41

回答

1

我找到了正確的答案給我的問題。 表達

doc.Load("TeleneUdaje.rpt") 

是錯誤的,因爲它需要的.rpt文件這樣的完整路徑:

doc.Load("C:\\report.rpt"); 

THX徵求意見傢伙