I've solved this on my own. Here's the code (not adjusted to be readable -
you should be able to figure it out):
Make sure you're referencing and "using"
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
ReportDocument crReportDocument = new ReportDocument();
ExportOptions crExportOptions;
DiskFileDestinationOptions crDiskFileDestinationOptions;
ConnectionInfo crConnectionInfo;
foreach (XmlNode xn in xl)
{
if (xn.Attributes["Name"].Value.ToLower().Trim() ==
sReportName.ToLower().Trim())
{
//run the report
//set connection settings (stupid Crystal)
crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName =
xn.SelectSingleNode("ConnectionInfo").Attributes["Server"].Value;
crConnectionInfo.DatabaseName =
xn.SelectSingleNode("ConnectionInfo").Attributes["Database"].Value;
crConnectionInfo.UserID =
xn.SelectSingleNode("ConnectionInfo").Attributes["User"].Value;
crConnectionInfo.Password =
xn.SelectSingleNode("ConnectionInfo").Attributes["Password"].Value;
//load the report
crReportDocument.Load(xn.SelectSingleNode("Locatio n").InnerText);
//stupid Crystal Reports requirement - set the login information for every
table.
Tables crTables = crReportDocument.Database.Tables;
foreach (Table crTable in crTables)
{
TableLogOnInfo crTableLogonInfo = crTable.LogOnInfo;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogonInfo);
}
//Set the export destination
crDiskFileDestinationOptions = new DiskFileDestinationOptions();
string sExportFileName = Application.StartupPath + "\\" +
xn.Attributes["Name"].Value.Trim() + " " + DateTime.Now.ToString("dd") + "-"
+ DateTime.Now.Month + "-" + DateTime.Now.Year + " at " + DateTime.Now.Hour
+ "." + DateTime.Now.Minute + "." + DateTime.Now.Second + ".pdf";
crDiskFileDestinationOptions.DiskFileName = sExportFileName;
//'Set the exporting information
crExportOptions = crReportDocument.ExportOptions;
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
//Export the report
crReportDocument.Export();
}
}
"Matt M" <matt@remove_this_core49.com> wrote in message
news:bEUYc.265023$M95.177241@pd7tw1no...
Hey... I'm trying to run a crystal report (8.5) from a c# windows forms
application class. I can't use the report viewer as the application will
be running these reports from a command line interface (for daily report
generation). I have looked high and low for some samples and/or some help
on what references to use, how to even create a report object etc, but to
no avail. Can anybody please help me (links to references would be just
dandy). I know, there's probably a newsgroup for this in particular, but
I couldn't find it.
Thanks.