i have some problems in exporting crystal reports to pdf. My program crashes at the load of teleneUdaje.rpt and i am shure it is the right name.
if (txtpath.Text == “”) throw new Exception(“Prosím zvoľte cieľ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á");
Please help.
** Edited
It throws Crystal Reports exception that the load of report failed. The File is OK because, within the program i can show reports with report viewer tool.
I found the correct answer to my question.
the expression
is wrong because it needs the full path to the .rpt file like this:
thx for comments guys