Select a Printer in page

Posted on 2005-05-04
Last Modified: 2008-01-09
I am trying to print a ReportDocument (Crystal Reports) using the ReportDocument.PrintToPrinter() function. The first parameter that this function needs is the printer name to which the document should be printed. I am trying to use the System.Windows.Forms.PrintDialog class to open up a print dialog and use it to set the printer to which the document should be printed. Here is my code:

ReportDocument rd = LoadReport(litFileName.Text); // Function to generate report document
System.Windows.Forms.PrintDialog pDlg = new System.Windows.Forms.PrintDialog();
pDlg.AllowSomePages = true;
pDlg.ShowHelp = true;

if (pDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
      rd.PrintOptions.PrinterName = pDlg.PrinterSettings.PrinterName;
      int numOfCopies = pDlg.PrinterSettings.Copies;

When I run this code, I get the following error (thrown on the ShowDialog() method call): "It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application."

After doing some web-searching, it seems that you cannot open a Windows.Forms dialog/message box through an application.

Is this true? If so, how can I find out the name of the user's default printer in order that I can send this to ReportDocument.PrintToPrinter()??
Question by:jellis613
    LVL 10

    Accepted Solution

    You cant control cliend side applicationr or dialogs from page.

    You cant send automatically to the client printer.! It just not possible. User must interact with their internet explorer printer dialog!. They must chooese.

    If you could do that, ! Imagine the risk of making pages!

    You will have to make winforms or smart client applications.

    LVL 2

    Author Comment

    all I need is the name of the person's default printer. Is there some way that I can parse the list of printers available for this person to use on their computer and then let the user select which printer they would like to print to?
    LVL 23

    Assisted Solution

    You cannot get anything relating to the printer from Internet Explorer. This is not a coding issue, it is a security one. If any browser were to be allowed to do this without the knowledge and consent of the end-user, it would be considered a serious breach of security for the browser.

    On the other hand, you can write an ActiveX Object which will be able to get the default printer name and pass that to the server via a postback.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now