Determining the Default Printer

D

David C. Barber

my.computer.printers.defaultprinter doesn't exist in 2005, despite the
plethora of examples still out on the web detailing its use.

So how can I determine a person's default printer using ASP 2?

Thanks!
 
M

Mark Rae [MVP]

my.computer.printers.defaultprinter doesn't exist in 2005, despite the
plethora of examples still out on the web detailing its use.

So how can I determine a person's default printer using ASP 2?

You can't - ASP.NET has no way of interfacing directly with the hardware on
the machine on which the client browser is running...

What use would this information be anyway...?
 
D

David C. Barber

Mark Rae said:
You can't - ASP.NET has no way of interfacing directly with the hardware on
the machine on which the client browser is running...

What use would this information be anyway...?

I have a user printing out of the Crystal Reports Viewer control version XI
R2. I need to know when they are printing, and unlike the VB6 version of
this control where you could trap the Print Event on the control itself,
there is no option for that in ASP that I've been able to determine. As
such, I need to add my own print button to the form, and trigger the
control's .printreport method. Because the user is printing on a special
form at this time, they may not be using their normal printer. While I can
control the printer name to use for printing as part of the Crystal Report
Viewer control, I can allow them to select a desired printer by going
through the system.printers collection and creating a drop-down list of
possible printers. At least I can do this when running in development on my
own machine. I've yet to try this from the IIS server, but will be doing so
soon. I'd like to offer up their default printer as the first choice, but
haven't been able to determine which of the several printers they may have
installed that this one is. Printing to the default printer hasn't been a
problem, since if I don't set any printer at all, it goes to default.
Still, I'd also like to log the printer used, but don't know what that
printer is.

The beta's of VS 2005 promised me that this would all be so very easy with
my.computer.printers and my.computer.printers.defaultprinter, and then they
ripped it away from me in the release version.

Even if it's harder to determine the default printer for a user, it should
hardly be impossible. But I don't know what to try next in this regard, and
was hoping for some help here.

When you need to track when and where a user prints controlled documents,
knowing this information can be very useful indeed.
 
M

Mark Rae [MVP]

I have a user printing out of the Crystal Reports Viewer control version
XI
R2. I need to know when they are printing, and unlike the VB6 version of
this control where you could trap the Print Event on the control itself,
there is no option for that in ASP that I've been able to determine.

Indeed not... WinForms and WebForms are *totally* different... When a
webserver (IIS or whatever) streams down a page to a client browser, it has
no further interaction with that client browser until / unless that client
browser sends it another HttpRequest - there is no permanent connection...

Controlling and querying printers is a breeze in a WinForms app because the
app is running on the local machine. This isn't the case with ASP.NET, which
runs on a webserver not the client machine.
Even if it's harder to determine the default printer for a user, it should
hardly be impossible. But I don't know what to try next in this regard,
and
was hoping for some help here.

Natively, you have no chance whatsoever of doing this... As I said, a web
application has no way of interfacing natively with the hardware on which
the client browser is running - in fact, all modern browsers are designed
specifically to prevent this, for fairly obvious security reasons...

Your only hope would be to use something like WSH, but that would only work
in IE (it's ActiveX) and would require you to seriously ramp down your
security - I can't advise you to even consider this...
 
J

Juan T. Llibre

re:
!> Natively, you have no chance whatsoever of doing this... As I said, a web
!> application has no way of interfacing natively with the hardware on which
!> the client browser is running - in fact, all modern browsers are designed
!> specifically to prevent this, for fairly obvious security reasons...

A wet dream if I've ever seen one.
Just imagine a web app which can trigger millions of client printers to start printing.

:)

Enabling a client to print a page, with the ability
to select a printer they have installed, is as simple as :

<input type="button" value="Print" onClick="window.print()">
or
<a href="javascript:window.print()">Print</a>

If you don't want to show the button, or the text "Print", you could use :

<body onLoad="window.print()">
....and advice the user that the printer dialog will be shown, in the referring link.

While asp.net developers deal mainly with server events,
it's easy to downstream a choice to a client using Javascript.
 
M

Mark Rae [MVP]

re:
!> Natively, you have no chance whatsoever of doing this... As I said, a
web
!> application has no way of interfacing natively with the hardware on
which
!> the client browser is running - in fact, all modern browsers are
designed
!> specifically to prevent this, for fairly obvious security reasons...

A wet dream if I've ever seen one.
Just imagine a web app which can trigger millions of client printers to
start printing.
Indeed!

:)

Enabling a client to print a page, with the ability
to select a printer they have installed, is as simple as :

Ah yes, but that's not what the OP wants... The OP wants some way of
interrogating the hardware settings on the machine on which the client
browser is running to find out the name of the default printer - and that's
just not going to happen natively...
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top