Server Printing using Print Dialog

B

BrassicaNigra

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
 
S

Steven Cheng [MSFT]

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:
(e-mail address removed).

==================================================
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]" <[email protected]>
References: <[email protected]>
In-Reply-To: <[email protected]>
Subject: Re: Server Printing using Print Dialog
Date: Wed, 9 Jul 2008 00:34:48 +0100
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"]
}
}
}
 
B

BrassicaNigra

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 said:
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"]
}
}
}
 
B

BrassicaNigra

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 said:
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"]
}
}
}
 
S

Steven Cheng [MSFT]

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:
(e-mail address removed).

==================================================
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==?= <[email protected]>
References: <[email protected]>
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 said:
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"]
}
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top