none
Print doesn't start online RRS feed

  • Question

  • Hi all,

     

    I'm trying to print a report without the reportviewer using AS.NET and VB . I found an example and it works fine offline but when I upload my web page it doesn't start the print.

     

    Private 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(Path.GetTempPath.ToString() + name + "." + fileNameExtension, ileMode.Create)

          m_streams.Add(stream)

          Return stream

    End Function

     

    The original function trow me an exception saying that "access path to the file '..." is denied" and I have change it to the temp dir path using Path.GetTempPath.ToString(). Now there is no error information but it doesn't starts the print

     

    Any ideas ?

     

    Thanks in avance for any help

    Jorge

    Monday, March 24, 2008 1:27 AM

All replies

  • The code you posted only handles retrieving the EMF file for each page of the report.  You still need to send it to the printer yourself.  You can also use the built in printing functionality.  The VS 2005 webforms viewer has support for printing when running in server mode.  And we added support for printing from local mode webforms in VS 2008.
    Wednesday, March 26, 2008 9:41 PM
    Moderator
  •  

    Thanks for the reply Brian.

    Thats the problem ... it print on the local machine but not on the server. I thoght the problem comes from that code but I really don't know now. Do you have any example (or link) that show me how can I do that ? I

    I only want to give the end users the possibility to print some nice reports ... but I think i'm printing on the server print and not on the local printers (users)

    Thanks once again for your help

    jpaulino


    Here's what I have:

    Code Snippet

    Imports System.IO

    Imports System.Data

    Imports System.Text

    Imports System.Drawing.Imaging

    Imports System.Drawing.Printing

    Imports System.Collections.Generic

    Imports Microsoft.Reporting.WebForms

    Imports ClassSQL

    Imports System.Data.SqlClient

     

    Public Class Demo

    Implements IDisposable

     

    Private m_currentPageIndex As Integer

    Private m_streams As IList(Of Stream)

     

    Private 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(Path.GetTempPath.ToString() + name + "." + fileNameExtension, FileMode.Create)

    m_streams.Add(stream)

    Return stream

    End Function

     

    Private Sub Export(ByVal report As LocalReport, ByVal lbl As Label)

    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)()

    Try

    report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)

    Catch e As System.Exception

    Dim inner As Exception = e.InnerException

    lbl.Visible = True

    While Not (inner Is Nothing)

    lbl.Text &= inner.Message + vbNewLine

    inner = inner.InnerException

    End While

    End Try

    Dim stream As Stream

    For Each stream In m_streams

    stream.Position = 0

    Next

    End Sub

     

    Private 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

    Private Sub Print()

    'Const printerName As String = "Microsoft Office Document Image Writer"

    'printDoc.PrinterSettings.PrinterName = printerName

    If m_streams Is Nothing Or m_streams.Count = 0 Then

    Return

    End If

    Dim printDoc As New PrintDocument()

    If Not printDoc.PrinterSettings.IsValid Then

    Dim msg As String = "Can't find any printer"

    Throw New Exception(msg)

    Return

    End If

    AddHandler printDoc.PrintPage, AddressOf PrintPage

    printDoc.Print()

    End Sub

     

    Public Sub Run(ByVal lbl As Label)

    Dim report As LocalReport = New LocalReport()

    report.ReportPath = "administracao\TestReport.rdlc"

    Dim dr As SqlDataReader = ExecuteReader("SELECT * FROM ANDARES")

    report.DataSources.Add(New ReportDataSource("DataSet1_andares", dr))

    Export(report, lbl)

    m_currentPageIndex = 0

    Print()

    End Sub

     

    Public Overloads Sub Dispose() Implements IDisposable.Dispose

    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

     

    End Class

     

     

     

    Thursday, March 27, 2008 11:37 PM