By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,678 Members | 2,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,678 IT Pros & Developers. It's quick & easy.

Server Printing using Print Dialog

P: n/a
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
Jul 8 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"BrassicaNigra" <br************@community.nospamwrote in message
news:CB**********************************@microsof t.com...
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

Jul 8 '08 #2

P: n/a
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:
ms****@microsoft.com.

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

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Mark Rae [MVP]" <ma**@markNOSPAMrae.net>
References: <CB**********************************@microsoft.co m>
In-Reply-To: <CB**********************************@microsoft.co m>
Subject: Re: Server Printing using Print Dialog
Date: Wed, 9 Jul 2008 00:34:48 +0100
>
"BrassicaNigra" <br************@community.nospamwrote in message
news:CB**********************************@microso ft.com...
>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

Jul 9 '08 #3

P: n/a
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" <br************@community.nospamwrote in message
news:CB**********************************@microsof t.com...
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

Jul 9 '08 #4

P: n/a
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" <br************@community.nospamwrote in message
news:CB**********************************@microsof t.com...
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

Jul 9 '08 #5

P: n/a
"BrassicaNigra" <br************@community.nospamwrote in message
news:BF**********************************@microsof t.com...

[top-posting corrected]
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.
Because System.Management is not one of the default namespaces which are
referenced when projects are created...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 9 '08 #6

P: n/a
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:
ms****@microsoft.com.

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

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

--------------------
>From: =?Utf-8?B?QnJhc3NpY2FOaWdyYQ==?= <br************@community.nospam>
References: <CB**********************************@microsoft.co m>
<un**************@TK2MSFTNGP02.phx.gbl>
>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" <br************@community.nospamwrote in message
news:CB**********************************@microso ft.com...
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

Jul 10 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.