473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Server Printing using Print Dialog

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
6 4539
"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
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: gerb | last post by:
Hello, I realise this is not a pure Javascript question, and that VBscript is probably involved at some point, though not as much as I fear. If you opened this item looking for a pute Javascript...
3
by: Jon Vaughan | last post by:
Hi, I have written some code using the printdocument object, the code works fine , but when the printer is printing an xp dialog box appears ( same one that appears when you print in notepad )...
1
by: hellohez | last post by:
We are currently looking into triggering printing of an HTML file to a designated printer in such a way that the print dialog box is not viewed. It is possible to use the print method of a default...
3
by: John Peterson | last post by:
Hello all! I'm at my wits end trying to search for what I assumed to be a relatively straightforward task. I have a Web application written in C#, and I have a button on the form that I want to...
4
by: sachin | last post by:
Hi I am working on report using print preview dialog control in windows application. Report is displayed properly in control. With paper size 850X1350 (Legal)(Lanscape mode=true) . But when...
2
by: Brad Pears | last post by:
I have some sample code that uses the print dialog, print preview and a print direct options. If I select print preview and then click the printer icon from that, the document prints. If I...
3
by: brvan41 | last post by:
It's me again, you guys really helped a lot the last time I posted, and was needing a little more help. I've got 2 comboxes and a listbox. The user selects from the 2 and is being displayed in...
0
by: =?Utf-8?B?QnJhc3NpY2FOaWdyYQ==?= | last post by:
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...
0
by: Andrew Meador | last post by:
I have implemented a printing scenario where an html file is printed using the the following code: public void PrintHtmlFile(string url) { RegistryKey IERegKey; string header = null; string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.