Link to home
Start Free TrialLog in
Avatar of fantasylan
fantasylan

asked on

How do I send crystal report from c sharp console application?

Hello,

I have a ASP.net C sharp console application. I added and created a crystal report at design time and linked it to my SQL server database. Now, I want to distribute it by email(SMTP) through the console application. How can I do this? Can I send it as PDF and a RPT ?
Code snippets would be very helpful.

Regards
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

I have a ASP.net C sharp console application
Is it a web site application, or a program that runs on a computer in a "DOS" box?
 
You should be able to export your Crystal Report as a PDF, then attach it to an e-mail.
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fantasylan
fantasylan

ASKER

Hi tgerbert,

I got a run time error with the following text:

"Load report failed."

Any suggestions. The crystal report that I created is also called "CrystalReport1.rpt".  Do I have to pass a specific path here in  report.Load("CrystalReport1.rpt") ?
>>Do I have to pass a specific path here in  report.Load("CrystalReport1.rpt")

Yes
Hi emoreau,

The file is  located in the root folder. I tried
String path = HttpContext.Current.Request.MapPath("~/CrystalReport1.rpt") and
path = HttpContext.Current.Server.MapPath("~/CrystalReport1.rpt");

but I am getting a simple Null reference error which I cant seem to figure out.

Please help.

Regards.
So, it's an ASP.Net web application - not a console application?
I think Server.MapPath("~/anyfile.ext") would return a file path, whether the file exists or not.
Can you put a breakpoint in your code and verify "path" is being correctly set, and that the Crystal Report actually exists where "path" thinks it does?
Hi tgerbert,

It is a console application.

I tried your code but I was getting the "File Not found" error, so i tried it this way but it IS a console application.
Then you can't use Server.MapPath or Request.MapPath, they're exlusively for use in a web site application (your null reference exception is because the "Server" and "Request" objects are both null).
In Visual Studio, in the Solution Explorer section, select your Crystal Report; then in the properties window for that file change the "Copy to Output" setting to "If Newer"
By default, the report does not get copied to the \bin\debug or \bin\release folder along with your .EXE.
Hi tgerbert,

Thanks... I got through that step but I got stuck on the next one which says "logon failed for user sa".

Regards,

Nitin
You need to provide a database login for your report.  I'm not sure off the top of my head how that's done when using a SQL database.
I have done that and I can preview the report in Visual Studio itself. Its only when  I run the application that I am getting the error.

Regards.

report.SetDatabaseLogon("sa", "secret");