473,395 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Crystal Reports - sorry to bring the pain

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.
Nov 16 '05 #1
1 1686
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.

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ashish Shridharan | last post by:
Hi All, I'm not very sure if this is the forum for my question but i was hoping someone could direct me to the right place (or answer my question). I am using the .NET crystal report viewer...
7
by: Phin | last post by:
I need your HELP! I've seen all the posts on using Crystal Reports within vs.net (vb.net) and changing a SQL query at runtime. When I tried to pass in a dataset into the crystal report at...
4
by: chuckdfoster | last post by:
I am having a problem with moving my web app that uses Crystal Reports to our web server. I do not have administrative rights to the web server. When my site gets moved from my local machine to...
4
by: MadCrazyNewbie | last post by:
Hey Again Group, Sorry to be a pain but .......... I have a Windows Forms Project with serveral reports in now. At the moment I have 7 Forms all Called Print1, Print2, Print3 and so on....
2
by: fig000 | last post by:
Hi everyone, I recently wrote a vb.net app which includes some crystal reports. The user has very little money in their budget and have been without a working application for quite a while. This...
17
by: Peter Proost | last post by:
Hi Group, I've got an interesting problem, I don't know if this is the right group but I think so because everything I've read about it so far says it's a .net problem. Here's the problem, we're...
4
by: Mike | last post by:
Hi We are developing an ASP.NET 2.0 application and using the in built Crystal report system that it comes with. We have everything running fine on our development server but when we publish...
6
by: Miro | last post by:
I can run an exe ( and its install ) i have created on my machine. The exe has a button that populates a dataset and then shoots it to a crystal report. But... Installing the setup.exe on my...
4
by: Miro | last post by:
<i have also added this reply to the other newsgroup - now that I have realizd ( and assuming ) it is not a localized error directly to vb.> I have found this link on the website:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.