Click here to Skip to main content
15,908,776 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: A login problem Pin
Farhad Eft31-Mar-11 21:23
Farhad Eft31-Mar-11 21:23 
GeneralRe: A login problem Pin
Farhad Eft31-Mar-11 21:26
Farhad Eft31-Mar-11 21:26 
GeneralRe: A login problem Pin
C#Coudou3-Apr-11 22:13
C#Coudou3-Apr-11 22:13 
AnswerRe: A login problem [modified] Pin
davidnz2-Apr-11 10:57
davidnz2-Apr-11 10:57 
AnswerRe: A login problem Pin
SamRST4-Apr-11 21:19
SamRST4-Apr-11 21:19 
QuestionProblem with a require input field DropDownList if old records have null in this field Pin
kbalias31-Mar-11 20:42
kbalias31-Mar-11 20:42 
AnswerRe: Problem with a require input field DropDownList if old records have null in this field Pin
ktrrzn5-Apr-11 15:39
ktrrzn5-Apr-11 15:39 
QuestionHelp how to get the list of printer in the client computer Pin
C#Coudou31-Mar-11 15:17
C#Coudou31-Mar-11 15:17 
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.Position = 0
            Next

        Catch ex As Exception
            Dim inner As Exception = ex.InnerException
            While Not (inner Is Nothing)
                'MsgBox(inner.Message)
                inner = inner.InnerException
            End While
        End Try

    End Sub
    'metafile
    Public Sub PrintPage(ByVal sender As Object, _
    ByVal ev As PrintPageEventArgs)
        Dim pageImage As New Metafile(m_streams(m_currentPageIndex))
        ev.Graphics.DrawImage(pageImage, ev.PageBounds)

        m_currentPageIndex += 1
        ev.HasMorePages = (m_currentPageIndex < m_streams.Count)
    End Sub
   'print
    Public Sub Print()
        Dim printerName As String = DefaultPrinterName()
        If m_streams Is Nothing Or m_streams.Count = 0 Then
            Return
        End If

        Dim printDoc As New PrintDocument()
        printDoc.PrinterSettings.PrinterName = printerName
        If Not printDoc.PrinterSettings.IsValid Then
            Dim msg As String = String.Format("Can't find printer ""{0}"".", printerName)
            'Console.WriteLine(msg)
            Return
        End If
        AddHandler printDoc.PrintPage, AddressOf PrintPage
        printDoc.Print()

        If Not (m_streams Is Nothing) Then
            Dim stream As Stream
            For Each stream In m_streams
                stream.Close()
            Next
            m_streams = Nothing
        End If        
    End Sub
----FUNCTION ------
   Public Function DefaultPrinterName() As String
        Dim oPS As New System.Drawing.Printing.PrinterSettings

        Try
            DefaultPrinterName = oPS.PrinterName
        Catch ex As System.Exception
            DefaultPrinterName = ""
        Finally
            oPS = Nothing
        End Try
    End Function


Unfortunately, this code will work only in the server, instead to the client computer.
I want a solution/way/approach on how to get the client printer? I want to print an rdlc report at any client not only on the server.

Thank you in advance.
C# コードMicrosoft End User
2000-2008




「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」


AnswerRe: Help how to get the list of printer in the client computer Pin
Not Active31-Mar-11 16:59
mentorNot Active31-Mar-11 16:59 
GeneralRe: Help how to get the list of printer in the client computer Pin
C#Coudou31-Mar-11 18:07
C#Coudou31-Mar-11 18:07 
GeneralRe: Help how to get the list of printer in the client computer Pin
Not Active1-Apr-11 0:59
mentorNot Active1-Apr-11 0:59 
Questiondocument.getElementById Not work With Masterpage ASP.Net VB Pin
Diyaa Hamza31-Mar-11 10:02
Diyaa Hamza31-Mar-11 10:02 
AnswerRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
El_Programmer31-Mar-11 10:53
El_Programmer31-Mar-11 10:53 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Diyaa Hamza31-Mar-11 11:01
Diyaa Hamza31-Mar-11 11:01 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
El_Programmer31-Mar-11 11:11
El_Programmer31-Mar-11 11:11 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Not Active31-Mar-11 11:54
mentorNot Active31-Mar-11 11:54 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
El_Programmer31-Mar-11 12:01
El_Programmer31-Mar-11 12:01 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Not Active31-Mar-11 12:05
mentorNot Active31-Mar-11 12:05 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Not Active31-Mar-11 12:01
mentorNot Active31-Mar-11 12:01 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Diyaa Hamza31-Mar-11 12:34
Diyaa Hamza31-Mar-11 12:34 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Not Active31-Mar-11 13:26
mentorNot Active31-Mar-11 13:26 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
ktrrzn5-Apr-11 15:51
ktrrzn5-Apr-11 15:51 
AnswerRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
GenJerDan31-Mar-11 17:27
GenJerDan31-Mar-11 17:27 
QuestionHelp with regular expression for reg ex validator Pin
TimWallace31-Mar-11 7:50
TimWallace31-Mar-11 7:50 
AnswerRe: Help with regular expression for reg ex validator Pin
Not Active31-Mar-11 8:15
mentorNot Active31-Mar-11 8:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.