Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Help how to get the list of printer in the client computer

Help how to get the list of printer in the client computer

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netgraphicssysadmindebugging
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    C Coudou
    wrote on last edited by
    #1

    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 ReportViewer

            rptViewer = 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 IDisposable

    Public 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.
    
    N 1 Reply Last reply
    0
    • C C Coudou

      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 ReportViewer

              rptViewer = 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 IDisposable

      Public 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.
      
      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      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

      C 1 Reply Last reply
      0
      • N Not Active

        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

        C Offline
        C Offline
        C Coudou
        wrote on last edited by
        #3

        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 」」」」」」」」」」」」」」」」」」」」」」」」」」」」

        N 1 Reply Last reply
        0
        • C C Coudou

          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 」」」」」」」」」」」」」」」」」」」」」」」」」」」」

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups