相关文章推荐
调皮的小蝌蚪  ·  Laravel ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Error while printing crystal report, with that exception message "No printers are installed"

Ask Question

I got an exception with message "No printers are installed." while printing a report for depolyed release of our website.
I use _rptDocument.PrintToPrinter(1, false, 0, 0); to print a report.

I got that exception, even I've more than one printer installed on my machine. Also, I don't get that exception while development, everything while development is going fine.

I used "Publish Web Site" and "Web Project Deployment" options to publish/deploy website, but I got the same result.

Any suggestions?

Sample Code

DataSet dsResult = null;
rptDocument = new ReportDocument();
rptDocument.Load(Server.MapPath("WINGR0040.rpt"));
// Fetch report data.
rptDocument.SetDataSource(dsResult);
// Print report.
rptDocument.PrintToPrinter(1, false, 0, 0);
                Can you print this report if you use any of the Crystal Report Viewer controls?  Are you trying to print the report on the server?
– craig
                Apr 13, 2010 at 12:45
                No, I cannot print report using Crystal Report viewer. I tried to print the report, on the server, and on the client, but I got the same result as I described.
– Ahmed Atia
                Apr 13, 2010 at 19:55
                Export report to PDF will solve the issue, but that solution is not acceptable for customer. Using print button should print document directly, no need to export to it, he said.
– Ahmed Atia
                Jun 11, 2010 at 14:51
                For you to print from the server, is a security risk since by default the account iis uses for the app domains is restricted. Also this will only work in an intranet setting.
– ggonsalv
                Jun 11, 2010 at 21:05

Have you added a printer on the Web server under the user account that site runs under?

Have you tried setting the printer name first?

Report.PrintOptions.PrinterName = printerName;

If your site runs under an account e.g DOMAIN\WebService you need to ensure that this user account has a default printer.

You could also try setting the printer name like this:

Report.PrintOptions.PrinterName = this.printDocument1.PrinterSettings.PrinterName;

This will get the default printer.

This article may help you get this working.

EDIT:

This article on MSDN describes how printing can be acheived using Crystal Reports and ASP.NET. If you are not implementing either of these solutions then I don't think you will be able to print client side.

The .cab file mentioned in the MSDN link can be found here:

Visual Studio 2005 Visual Studio 2008

Without you posting further code and more detail as to how you are generating the report I don't I am going to be able to fully answer your question.

Thanks

Website is published on another server rather than client machine. For printer, both web server and client's machine have an installed printer. – Ahmed Atia Jun 7, 2010 at 18:31 Under the user account that the site runs? Also, this will print it from the server NOT the client. Is this what you want? – codingbadger Jun 8, 2010 at 6:57 No, I need to print report from client machine? For this, "Under the user account that the site runs?" do you mean that I should give certain permissions for every client machine, or what do you mean exactly? – Ahmed Atia Jun 8, 2010 at 14:57 The PrintDocument and PrinterSettings are for Windows Form projects only, or I missing something? – Ahmed Atia Jun 9, 2010 at 15:54 The title of the article is Printing Web based reports with Crystal Reports for Visual Studio .NET – codingbadger Jun 9, 2010 at 16:14

on Page_Load i got this:

foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
    DropDownList1.Items.Add(printer);

Now on button_click:

var dsTela = (DataSet)Session["dsTela"];
var cr = new ReportDocument();
var rpt = Request.QueryString["nomeRel"];
cr.Load(Server.MapPath("~/Crystal/" + rpt));
    //----------Crystal Reports---------------//
    // carrega o reltório
cr.SetDataSource(dsTela);
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
printerSettings.PrinterName = DropDownList1.SelectedValue;
cr.PrintToPrinter(printerSettings, new PageSettings(), false);

//this one works for me

If your printer don`t show in your server-side, try this one:

Source: (https://support2.microsoft.com/default.aspx?scid=kb;en-us;184291)

To enable IIS to enumerate the network printers by using the SYSTEM account, follow these steps.

Note If the process is running under the Network Service account, explicit permissions to the newly created registry are required.

  • Make sure that you are currently logged in to the server as a user who has the desired network printers installed.
  • Start Registry Editor.
  • Click the following key: HKEY_CURRENT_USER\Printers\Connections
  • On the Registry menu, click Export Registry File.
  • In the File Name box, type c:\printconns.reg.
  • To open the printconns.reg file in Notepad, click Start, click Run, type Notepad printconns.reg in the Open box, and then click OK.
  • Replace the text HKEY_CURRENT_USER with the text HKEY_USERS.DEFAULT.
  • Save the file.
  • To import the file into the registry, double-click the file in Windows Explorer.
  • Restart the Print Spooler service.
  • Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.