Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print with CR in .net

Status
Not open for further replies.

lutzs

Programmer
Oct 8, 2002
75
0
0
LU
Hi,

i've created an ado.net Dataset and can show it with the Crystal Reports Viewer.
Now, i will print the report.

I have implemented this code:

PageMargins margins;

margins = oRpt.PrintOptions.PageMargins;
margins.bottomMargin = 350;
margins.leftMargin = 350;
margins.rightMargin = 350;
margins.topMargin = 350;

oRpt.PrintOptions.ApplyPageMargins(margins);
oRpt.PrintOptions.PrinterName = "\\PRNLSHI\\EDVPRN5";

oRpt.PrintToPrinter(1, false,0,0);


oRpt is the report.
The printername is correct. I get this error message:

An unhandled exception of type 'CrystalDecisions.CrystalReports.Engine.InvalidArgumentException' occurred in crystaldecisions.crystalreports.engine.dll

Additional information: Error in File C:\DOCUME~1\Lulli\LOCALS~1\Temp\temp_8606af39-3797-44f0-be9e-748324ac17ac.rpt:
Invalid printer specified.

Thanks,
Stephanie
 
Try changing the line

oRpt.PrintOptions.PrinterName = "\\PRNLSHI\\EDVPRN5";

to

oRpt.PrintOptions.PrinterName = @"\\PRNLSHI\\EDVPRN5";

C# could be getting confused with the \'s

If this helps can you tell me how to close all forms in an application? They are all created from one parent and that parent is now hidden?
 
Hi,

i've changed the line to

oRpt.PrintOptions.PrinterName = @"\\PRNLSHI\\EDVPRN5";


The error message is the same:
An unhandled exception of type 'CrystalDecisions.CrystalReports.Engine.InvalidArgumentException' occurred in crystaldecisions.crystalreports.engine.dll

Additional information: Error in File C:\DOCUME~1\Lulli\LOCALS~1\Temp\temp_a0b4bccc-bbf8-4d9f-8028-01d28ad96146.rpt:
Invalid printer specified.

Is there a problem with my report?

Thanks,
Stephanie
 
Hmm not sure...

Have you tried creating a really simple report and printing that?
Is your report being dynamically created?
I presume you are creating a windows application and not a service or Internet site?

Try putting your report in the root directory "c:\" (it worked for me once?)

HTH
Gavin
 
Hi,

i create a report with ado.net: there is a dataset and the new crystal report file where i can insert my datafields.
The report is created and i can show it with the crystal report viewer.

For print i have this code:

PageMargins margins;

margins = oRpt.PrintOptions.PageMargins;
margins.bottomMargin = 350;
margins.leftMargin = 350;
margins.rightMargin = 350;
margins.topMargin = 350;

oRpt.PrintOptions.ApplyPageMargins(margins);
oRpt.PrintOptions.PrinterName "\\PRNLSHI\\EDVPRN5";
oRpt.PrintToPrinter(1, false,0,0);

And the error message is known.

I can't put the report in the root directory. It is saved in the project folder of my windows application.
Or: how can I put this report in the root directory?

Yes, i'm creating a windows application.

There are two files of my report:
CrystalReport1.rpt and
{3859DC5A-65EB-4EA3-B25B-B225E45665D9}.rpt in the same file directory.

The error message refers to the {3859DC5A-65EB-4EA3-B25B-B225E45665D9}.rpt file.

Thanks,
Stephanie
 
Well I only ever created the report using Crystal Reports itself so I am bit lost on a few things here.

Why is the one report name "{3859DC5A-65EB-4EA3-B25B-B225E45665D9}"? If you are using two reports make sure that you are setting the printer on both reports.

You may also want to check that whichever account is running your aspnet service has permission to access this printer.

The only other thing I can think of is make sure that the printer name is correct and that you are not using name that it is called on your computer.

Other than that I think I am out of ideas here?
Have you tried to print using a different report.

HTH
Gavin
 
I don't know why the one report name "{3859DC5A-65EB-4EA3-B25B-B225E45665D9}" is.
I use one report in my .net project.

The report "{3859DC5A-65EB-4EA3-B25B-B225E45665D9}" is created when I compile the project to create the CrystalReport1. Is it a temporary file?

Why I access nevertheless of the "{3859DC5A-65EB-4EA3-B25B-B225E45665D9}" file and not the CrystalReport1.rpt file?

Stephanie
 
...

I open the CrystalReport1.rpt with CR. I see the design view. When I click on preview, the windows installer is started.
I click Cancel and I get this error message:
"Failed to load database information.
Details: The database DLL "crdb_adoplus.dll" could not be loaded."
 
What you could try and do is run your report and then before you try print it. Save it to a location on your pc, then re-open it from that location and try print it then.

Also check how you are opening the report, I think there are options to open using temp copy or open exclusively, try play around with that a while.

If neither of these work you could try and export to .PDF and print from there?

HTH
Gavin
 
There exist an OpenReportMethod: byTempCopy and byDefault.

But I don't know: how I can it use?
 
When you load the report put it in this line
ReportDocument.LoadMethod(ReportName, byDefault)

or something like that....
 
Hi,

is it in the correct line to load the report by default?

This is the error message:

No overload for method 'Load' takes '2' arguments


oRpt = new CrystalReport1 ();

OleDbConnection oleConn = new OleDbConnection("Provider=MSDAORA.1;Password=pwd;User ID=user;Data Source=datasource");
OleDbDataAdapter oleAdapter = new OleDbDataAdapter("SELECT * FROM table", oleConn);

Dataset1 dataSet = new Dataset1();

//try to load the specified report file
oRpt.Load(oRpt, OpenReportMethod.OpenReportByDefault);

oleAdapter.Fill (dataSet, "i_cus");
oRpt.SetDataSource (dataSet);

crystalReportViewer1.ReportSource = oRpt;


Why isn't it fixed as default?

Thanks,
Stephanie
 
As you will see you need to add the line

oRpt.LoadMethod(oRpt, OpenReportMethod.OpenReportByDefault);

and then leave the oRpt.Load as normal.

I am not sure why it is not fixed to default? Maybe it is, Hopefully some intelligent person out there will jump in and point out the blatantly obvious :)
 
Don't assume that the printer name is correct. Win95/98 and WinNT/2000 take a different format for the printer name, so code that works in development can fail in production. See
Also, I've found that if you need one (PrinterName, PrinterPort, PrinterDriver) all three properties may need to be set. When I had this problem, I actually set all three to the same value -- the UNC printer name -- and it worked great for Win2000 machines.
 
Have you checked permissions on the shared printer to make sure you have rights to print to the spooler and are authenticated to the domain?
 
Did you find an answer to this problem? I seem to have the same thing happening to my app and I can't find a way to make it work properly. I've tried all this thread suggest before reading this and everything work fine except when I try to specify a printer. Printing on the default printer work.

Any hint?

Thanks!

Charles
 
Have you tried
oRpt.PrintOptions.PrinterName = @"\\PRNLSHI\EDVPRN5";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top