Server Printing using Print Dialog

Discussion in 'ASP .Net' started by BrassicaNigra, Jul 9, 2008.

  1. Greetings,

    I have a web application that prints a form using PrintDocument on the
    server. Currently it is set up to print to the default printer (on the
    server).

    My users would like to be able to select the printer (there are several on
    the network that the server can use).

    How can I bring up a print dialog box in the client browser that offers the
    different printers available to the server?

    If that is not possible, is there a way to retrieve the names of the
    printers on the server. I could then use the PrintSettings.PrinterName
    property to set the output myself, but would prefer the standard print dialog
    if possible.

    Thank you.

    Dale Hoffman
    BrassicaNigra, Jul 9, 2008
    #1
    1. Advertising

  2. Thanks for Mark's great inputs.

    Hi Dale,

    I agree with Mark that it is not allowed to display server-side printer
    setting interface to web application's client user(different machine or
    network boundary). The reasonable approach is use a web page to offer the
    user interface for the client user to choose the printer. You can first
    queries all the printers installed on the server machine and display in
    webpage to let the user choose one.

    Mark has also posted some good code snippet of using WMI to query the
    printers on the machine.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.


    --------------------
    >From: "Mark Rae [MVP]" <>
    >References: <>
    >In-Reply-To: <>
    >Subject: Re: Server Printing using Print Dialog
    >Date: Wed, 9 Jul 2008 00:34:48 +0100


    >
    >"BrassicaNigra" <> wrote in message
    >news:...
    >
    >> How can I bring up a print dialog box in the client browser that offers
    >> the
    >> different printers available to the server?

    >
    >You can't. Calling a dialog box on the server would pop a dialog box on

    the
    >server - there will be no-one there to see it...
    >
    >> If that is not possible, is there a way to retrieve the names of the
    >> printers on the server. I could then use the PrintSettings.PrinterName
    >> property to set the output myself

    >
    >Certainly. Because the code will be running on the server, you have the
    >entire .NET Framework at your disposal. There are several ways you can
    >retrieve the collection of printers installed on the server, but WMI is
    >probably the simplest:
    >
    >using System.Collections.Generic;
    >using System.Management;
    >
    >using (ManagementObjectSearcher objMOS = new
    >ManagementObjectSearcher("SELECT * FROM Win32_Printer"))
    >{
    > using (ManagementObjectCollection objMOC = objMOS.Get())
    > {
    > foreach (ManagementObject objMO in objMOC)
    > {
    > // do something with objMO["Name"]
    > }
    > }
    >}
    >
    >
    >--
    >Mark Rae
    >ASP.NET MVP
    >http://www.markrae.net
    >
    >
    Steven Cheng [MSFT], Jul 9, 2008
    #2
    1. Advertising

  3. Mark,

    This looks just like what I need, however when I used the code snippet I
    received an error that System.Management namespace does not exist. Is there
    something else I need to include?

    Dale

    "Mark Rae [MVP]" wrote:

    > "BrassicaNigra" <> wrote in message
    > news:...
    >
    > > How can I bring up a print dialog box in the client browser that offers
    > > the
    > > different printers available to the server?

    >
    > You can't. Calling a dialog box on the server would pop a dialog box on the
    > server - there will be no-one there to see it...
    >
    > > If that is not possible, is there a way to retrieve the names of the
    > > printers on the server. I could then use the PrintSettings.PrinterName
    > > property to set the output myself

    >
    > Certainly. Because the code will be running on the server, you have the
    > entire .NET Framework at your disposal. There are several ways you can
    > retrieve the collection of printers installed on the server, but WMI is
    > probably the simplest:
    >
    > using System.Collections.Generic;
    > using System.Management;
    >
    > using (ManagementObjectSearcher objMOS = new
    > ManagementObjectSearcher("SELECT * FROM Win32_Printer"))
    > {
    > using (ManagementObjectCollection objMOC = objMOS.Get())
    > {
    > foreach (ManagementObject objMO in objMOC)
    > {
    > // do something with objMO["Name"]
    > }
    > }
    > }
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
    BrassicaNigra, Jul 9, 2008
    #3
  4. Mark,

    I figured out the System.Management namespace issue. One question about
    this; normally I do not have to add a reference when using any of the system
    namespace items - usually just putting the 'using System.XXXX' at the top of
    the file is all I have to do. Why did I have to add a reference for this one.

    Thanks for your help.

    Dale

    "Mark Rae [MVP]" wrote:

    > "BrassicaNigra" <> wrote in message
    > news:...
    >
    > > How can I bring up a print dialog box in the client browser that offers
    > > the
    > > different printers available to the server?

    >
    > You can't. Calling a dialog box on the server would pop a dialog box on the
    > server - there will be no-one there to see it...
    >
    > > If that is not possible, is there a way to retrieve the names of the
    > > printers on the server. I could then use the PrintSettings.PrinterName
    > > property to set the output myself

    >
    > Certainly. Because the code will be running on the server, you have the
    > entire .NET Framework at your disposal. There are several ways you can
    > retrieve the collection of printers installed on the server, but WMI is
    > probably the simplest:
    >
    > using System.Collections.Generic;
    > using System.Management;
    >
    > using (ManagementObjectSearcher objMOS = new
    > ManagementObjectSearcher("SELECT * FROM Win32_Printer"))
    > {
    > using (ManagementObjectCollection objMOC = objMOS.Get())
    > {
    > foreach (ManagementObject objMO in objMOC)
    > {
    > // do something with objMO["Name"]
    > }
    > }
    > }
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
    BrassicaNigra, Jul 9, 2008
    #4
  5. H Dale,

    As for the referencing question you mentioned, as Mark has explained.

    For those classes that you only need to put "using XXXXX namespace " above
    the code, that is because the namespace is defined within an assembly your
    project has already referenced. for example, the .net project by default
    references several assemblies when you create the project such as:

    mscorelib.dll
    system.dll
    system.data.dll..
    ....

    For System.Management namespace, it is defined in another separate
    assembly, therefore, you need to manually import it into your project's
    reference list so that the IDE can get sense of any namespace of classes in
    that assembly(the intellisense will work then).

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------

    >From: =?Utf-8?B?QnJhc3NpY2FOaWdyYQ==?= <>
    >References: <>

    <>
    >Subject: Re: Server Printing using Print Dialog
    >Date: Wed, 9 Jul 2008 07:50:01 -0700


    >
    >Mark,
    >
    >I figured out the System.Management namespace issue. One question about
    >this; normally I do not have to add a reference when using any of the

    system
    >namespace items - usually just putting the 'using System.XXXX' at the top

    of
    >the file is all I have to do. Why did I have to add a reference for this

    one.
    >
    >Thanks for your help.
    >
    >Dale
    >
    >"Mark Rae [MVP]" wrote:
    >
    >> "BrassicaNigra" <> wrote in message
    >> news:...
    >>
    >> > How can I bring up a print dialog box in the client browser that

    offers
    >> > the
    >> > different printers available to the server?

    >>
    >> You can't. Calling a dialog box on the server would pop a dialog box on

    the
    >> server - there will be no-one there to see it...
    >>
    >> > If that is not possible, is there a way to retrieve the names of the
    >> > printers on the server. I could then use the PrintSettings.PrinterName
    >> > property to set the output myself

    >>
    >> Certainly. Because the code will be running on the server, you have the
    >> entire .NET Framework at your disposal. There are several ways you can
    >> retrieve the collection of printers installed on the server, but WMI is
    >> probably the simplest:
    >>
    >> using System.Collections.Generic;
    >> using System.Management;
    >>
    >> using (ManagementObjectSearcher objMOS = new
    >> ManagementObjectSearcher("SELECT * FROM Win32_Printer"))
    >> {
    >> using (ManagementObjectCollection objMOC = objMOS.Get())
    >> {
    >> foreach (ManagementObject objMO in objMOC)
    >> {
    >> // do something with objMO["Name"]
    >> }
    >> }
    >> }
    >>
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVP
    >> http://www.markrae.net
    >>
    >>

    >
    Steven Cheng [MSFT], Jul 10, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Peterson

    Printing from web form without print dialog.

    John Peterson, Jan 28, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    25,802
  2. JavaRookie
    Replies:
    4
    Views:
    1,651
    Gerbrand van Dieijen
    Oct 13, 2003
  3. mzo
    Replies:
    0
    Views:
    476
  4. keto
    Replies:
    0
    Views:
    903
  5. Matt
    Replies:
    1
    Views:
    269
    Randy Webb
    Nov 20, 2004
Loading...

Share This Page