Help how to get the list of printer in the client computer
-
Hi mates, I have a program in asp.net which will print a report viewer to the default printer. When the user clicked the print button. It will automatically print to default printer. I'm using the System.Drawing.Printing.PrinterSettings for getting the default printer. Here's the snippet code:
Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Try
Dim rptViewer As ReportViewerrptViewer = New ReportViewer With rptViewer.LocalReport .DataSources.Clear() .ReportPath = Server.MapPath("rptCert.rdlc") '(IM USING RDLC INSTEAD OF CR) .DataSources.Add(dataSource) .Refresh() End With myRPT= New CustPrint With myRPT .Export(rptViewer.LocalReport) .m\_currentPageIndex = 0 .Print() End With Catch ex As Exception log.Debug(ex.ToString) End Try
End Sub
----CLASS-----Public Class CustPrint
' Implements IDisposablePublic m\_currentPageIndex As Integer Public m\_streams As IList(Of Stream) Public stName As String 'create steam Public Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, \_ ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream Dim stream As Stream = New FileStream("C:\\" + name + "." + fileNameExtension, FileMode.Create) m\_streams.Add(stream) Return stream End Function 'Export Public Sub Export(ByVal report As LocalReport) Try Dim deviceInfo As String = \_ "<DeviceInfo>" + \_ " <OutputFormat>EMF</OutputFormat>" + \_ " <PageWidth>8.5in</PageWidth>" + \_ " <PageHeight>11in</PageHeight>" + \_ " <MarginTop>0.25in</MarginTop>" + \_ " <MarginLeft>0.25in</MarginLeft>" + \_ " <MarginRight>0.25in</MarginRight>" + \_ " <MarginBottom>0.25in</MarginBottom>" + \_ "</DeviceInfo>" Dim warnings() As Warning = Nothing m\_streams = New List(Of Stream)() report.Render("Image", deviceInfo, AddressOf CreateStream, warnings) Dim stream As Stream For Each stream In m\_streams stream.
-
Hi mates, I have a program in asp.net which will print a report viewer to the default printer. When the user clicked the print button. It will automatically print to default printer. I'm using the System.Drawing.Printing.PrinterSettings for getting the default printer. Here's the snippet code:
Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Try
Dim rptViewer As ReportViewerrptViewer = New ReportViewer With rptViewer.LocalReport .DataSources.Clear() .ReportPath = Server.MapPath("rptCert.rdlc") '(IM USING RDLC INSTEAD OF CR) .DataSources.Add(dataSource) .Refresh() End With myRPT= New CustPrint With myRPT .Export(rptViewer.LocalReport) .m\_currentPageIndex = 0 .Print() End With Catch ex As Exception log.Debug(ex.ToString) End Try
End Sub
----CLASS-----Public Class CustPrint
' Implements IDisposablePublic m\_currentPageIndex As Integer Public m\_streams As IList(Of Stream) Public stName As String 'create steam Public Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, \_ ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream Dim stream As Stream = New FileStream("C:\\" + name + "." + fileNameExtension, FileMode.Create) m\_streams.Add(stream) Return stream End Function 'Export Public Sub Export(ByVal report As LocalReport) Try Dim deviceInfo As String = \_ "<DeviceInfo>" + \_ " <OutputFormat>EMF</OutputFormat>" + \_ " <PageWidth>8.5in</PageWidth>" + \_ " <PageHeight>11in</PageHeight>" + \_ " <MarginTop>0.25in</MarginTop>" + \_ " <MarginLeft>0.25in</MarginLeft>" + \_ " <MarginRight>0.25in</MarginRight>" + \_ " <MarginBottom>0.25in</MarginBottom>" + \_ "</DeviceInfo>" Dim warnings() As Warning = Nothing m\_streams = New List(Of Stream)() report.Render("Image", deviceInfo, AddressOf CreateStream, warnings) Dim stream As Stream For Each stream In m\_streams stream.
That isn't how asp.net works. As you have discovered code-behind runs on the server not the client. The only way to use a client resouce such as a printer is to use ActiveX which is troublesome at best.
I know the language. I've read a book. - _Madmatt
-
That isn't how asp.net works. As you have discovered code-behind runs on the server not the client. The only way to use a client resouce such as a printer is to use ActiveX which is troublesome at best.
I know the language. I've read a book. - _Madmatt
i've searched on google with ActiveX and i found a code which will get the printers of server or client which is good.like this
var server="10.1.254.222"; 'change to client ip var shell = new ActiveXObject("wscript.shell"); var result = shell.Exec("net view \\\\" + server).StdOut.ReadAll(); var line = new Array(); ... and so on.
but the problem of the above code will get the list of printers which are shared.C# コードMicrosoft End User 2000-2008 「「「「「「「「「「「「「「「「「「「「「「「「「「「「 The best things in life are free 」」」」」」」」」」」」」」」」」」」」」」」」」」」」
-
i've searched on google with ActiveX and i found a code which will get the printers of server or client which is good.like this
var server="10.1.254.222"; 'change to client ip var shell = new ActiveXObject("wscript.shell"); var result = shell.Exec("net view \\\\" + server).StdOut.ReadAll(); var line = new Array(); ... and so on.
but the problem of the above code will get the list of printers which are shared.C# コードMicrosoft End User 2000-2008 「「「「「「「「「「「「「「「「「「「「「「「「「「「「 The best things in life are free 」」」」」」」」」」」」」」」」」」」」」」」」」」」」
It is generalyy a bad idea to use ActiveX control, they are difficult, cumbersome and prone to security issues. Users can disable them and admins can restritct them. They are also only usable in IE. Make the report available and let the use choose which printer.
I know the language. I've read a book. - _Madmatt