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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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("CrystalReport 1.rpt") ?
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("CrystalReport
>>Do I have to pass a specific path here in report.Load("CrystalReport 1.rpt")
Yes
Yes
ASKER
Hi emoreau,
The file is located in the root folder. I tried
String path = HttpContext.Current.Reques t.MapPath( "~/Crystal Report1.rp t") and
path = HttpContext.Current.Server .MapPath(" ~/CrystalR eport1.rpt ");
but I am getting a simple Null reference error which I cant seem to figure out.
Please help.
Regards.
The file is located in the root folder. I tried
String path = HttpContext.Current.Reques
path = HttpContext.Current.Server
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?
I think Server.MapPath("~/anyfile.
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?
ASKER
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.
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.
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.
ASKER
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
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.
ASKER
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.
Regards.
report.SetDatabaseLogon("s
You should be able to export your Crystal Report as a PDF, then attach it to an e-mail.