By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

Exporting Crystal Report in PDF on server side

P: n/a
Dear folks,

I was trying to write a .Net web application (using C#) that loads a
Crystal
Report on server side, export the report in PDF format as a file in
the web
server, and then serves up the file for clients to download. My code
was
working so far so good until I added ONE line.

Here's my working code so far:

---------------- (code start) -------------------------
System.Diagnostics.EventLog EventLog1 = new
System.Diagnostics.EventLog();

try
{
DiskFileDestinationOptions dFileDOpts = new
DiskFileDestinationOptions();

//string sSrcPath = this.MapPath("./BigReportTest.rpt");
string sSrcPath = this.MapPath("./2003_07_08_DLOTable.rpt");
//string sSrcPath = this.MapPath("./Sample_Report.rpt");

// Generate unique name for output file
StringBuilder sFileName = new
StringBuilder(DateTime.Now.ToShortDateString() + "_" +
DateTime.Now.ToShortTimeString() + "_" +
DateTime.Now.Millisecond.ToString());

sFileName.Replace(" ", "_");
sFileName.Replace(":", "_");
sFileName.Replace("/", "_");

string sResultFileName = sFileName.ToString();
string sDesPath = this.MapPath("./CRResult/" + sResultFileName +
"_BigFile.pdf");
ReportDocument oRD = new ReportDocument();
oRD.Load(sSrcPath);

dFileDOpts.DiskFileName = sDesPath;

ExportOptions eOpts = new ExportOptions();
eOpts = oRD.ExportOptions;
eOpts.ExportDestinationType = ExportDestinationType.DiskFile;
eOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
eOpts.DestinationOptions = dFileDOpts;

oRD.Export();
oRD.Close();

if (!System.Diagnostics.EventLog.SourceExists("MyApp1 "))
System.Diagnostics.EventLog.CreateEventSource(
"MyApp1", "Application");
EventLog1.Source = "MyApp";
EventLog1.WriteEntry ("Crystal Report pdf export success.");

}
catch(Exception fu)
{
if (!System.Diagnostics.EventLog.SourceExists("MyApp1 "))
System.Diagnostics.EventLog.CreateEventSource(
"MyApp1", "Application");
EventLog1.Source = "MyApp";
EventLog1.WriteEntry ("Something wrong with Crystal Report Load
Test!" + fu.Message);
};

---------------- (code end) -------------------------

After running, I got a pdf file in the CRResult folder. So far so
good. But
the report was NOT UPDATED to the latest change in the database. So I
added one
line to do REfresh:

.......
oRD.Load(sSrcPath);
oRD.Refresh(); // This is what I added
.......

Well, I got an error on the "oRD.Export()" line after at:

"Query Engine Error on line xxxxx"
So what did I do wrong? Is there any other way to get the refresh
view of the
report. And how come the data was not automatically pull form
database?

BTW, the report contains simply the content of a database table in a
Oracle 9i
Release 2 database. Maybe I don't need to a refresh if I reference to
a Stored
Procedure instead of pointing to a database table directly?

Any suggestions are welcomed. Thanks!!
Deecay
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: 1
Deecay,

If you save the data with your report, Crystal will not refresh the data if the parameters supplied are the same, unless you add the .refresh() method call, as you did. If you edit your report, unchecking the "save data with report" option, and remove the .refresh() method call, chances are you will get the same error when running the export. Do you have more specifics on the Query Engine error? Does it specify the problem, such as "Logon Failure"?
Jul 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.