none
ServerReport and WebForms direct printing RRS feed

  • Question

  • Hi all,

     

    I have been struggling with this all day, I have seen various posts and example showing how to use the WinForms and LocalReport to print a report directly to the printer without displaying a preview, but I have found little on the ServerReport and WebForms combination. At one point I was able to succesfully print but I wasn't able to print the barcode (the value was printing and not the font). After making some changes I thought would fix the barcode problem, I could no longer render the report to create the stream. Does anyone have an example of how to print directly to a printer using WebForms and ServerReport?

     

    Thanks,

    Simone

     

    P.S.

    Here is the code I borrowed(and slightly altered...)

    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

    Public Class clsPrintReport_PickingList

    Implements IDisposable

    Private _Printer As String

    Dim iPageCount As Integer

    Dim Report As ReportViewer

     

    Public Property pPrinter() As String

    Get

    Return _Printer

    End Get

    Set(ByVal value As String)

    _Printer = value

    End Set

    End Property

    Private m_currentPageIndex As Integer

    Private m_streams As IList(Of Stream)

    Private _Rendered As Byte()

    Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)

    Try

    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)

    Catch ex As Exception

    End Try

    End Sub

    Private Sub Print()

    Try

    If m_streams Is Nothing Or m_streams.Count = 0 Then

    Return

    End If

    Dim printDoc As New PrintDocument()

    printDoc.PrinterSettings.PrinterName = _Printer

    If Not printDoc.PrinterSettings.IsValid Then

    Dim msg As String = String.Format("Can't find printer ""{0}"".", _Printer)

    Console.WriteLine(msg)

    Return

    End If

    AddHandler printDoc.PrintPage, AddressOf PrintPage

    printDoc.Print()

    Catch ex As Exception

    End Try

    End Sub

    Private Sub Render(ByVal Report As ServerReport)

    Dim warnings As Warning() = Nothing

    Dim streamids As String() = Nothing

    Dim mimeType As String = Nothing

    Dim encoding As String = Nothing

    Dim extension As String = Nothing 'Nothing

    Dim deviceInfo As String

    Dim Format As String = "Image"

    deviceInfo = _

    "<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 streamid As String

    Try

    m_streams = New List(Of Stream)()

    _Rendered = Report.Render(Format, deviceInfo, mimeType, encoding, extension, streamids, warnings)

    Dim stream As New FileStream("..\..\" + "Main", FileMode.Create)

    stream.Write(_Rendered, 0, CInt(_Rendered.Length))

    m_streams.Add(stream)

    For Each streamid In streamids

    _Rendered = Report.RenderStream(Format, streamid, deviceInfo, mimeType, encoding)

    stream = New FileStream("..\..\" + streamid, FileMode.Create)

    stream.Write(_Rendered, 0, CInt(_Rendered.Length))

    m_streams.Add(stream)

    Next

    For Each stream In m_streams

    stream.Position = 0

    Next

    Catch ex As Exception

    End Try

    End Sub

    Public Sub Run()

    Try

    Report.ServerReport.ReportPath = "/folder/reportname"

    Report.ServerReport.ReportServerUrl = New Uri("http://server/ReportServer")

    Report.ServerReport.Refresh()

    Render(Report.ServerReport)

    m_currentPageIndex = 0

    Print()

    Catch ex As Exception

    End Try

    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

    Public Sub New()

    Report = New ReportViewer

    End Sub

    End Class

     

    Thursday, May 17, 2007 8:40 PM

Answers

  • Here is what I did to fix my issue:

     

    I changed the webservice account to a domain user account and I am now able to run the reports using the webforms control. I understand that the webforms control uses the web service, but why would it work using a domain account and not work using the Network Service account? Does anyone know?

     

    Thanks,

    Simone

    Friday, May 18, 2007 5:38 PM

All replies

  • I think my problem is outside of the issue above. I added a report viewer to a new page and directed it to the report server and report. I am receiving this error:

     

    The request failed with HTTP status 401: Unauthorized.

     

     

    Does anyone have any advice. I know this worked earlier yesterday.

    Thanks,

    Simone

    Friday, May 18, 2007 1:29 PM
  • Here is what I did to fix my issue:

     

    I changed the webservice account to a domain user account and I am now able to run the reports using the webforms control. I understand that the webforms control uses the web service, but why would it work using a domain account and not work using the Network Service account? Does anyone know?

     

    Thanks,

    Simone

    Friday, May 18, 2007 5:38 PM