none
.rdlc report exporting vb.net 2005Pro RRS feed

  • Question

  • Hi every one, I'm woking on a winApp and tring to print a report to the default PC printer through exporting to a PDF file.

    i have tried every solution online exampls. can see the the report in the reportViewer fine, but i get error says "An error occured during local report processing" and error source: " Microsoft.Reporting.WinForms" witch is alredy in the reference and imported.

    while tring to execute the line reportViewer.LocalReport.Render("PDF", "", "", "", "", Nothing, Nothing) 

    and defore i was getting PDF file with the Report headers but no details (no data)

    Am I missing a file or misplacing it (this is a windows form)

    herer is the code:

    Dim deviceInfo = String.Empty

    Dim format As String = "PDF"

    Dim rptViewer As New ReportViewer

    Dim encoding As String = String.Empty

    Dim mimeType As String = String.Empty

    Dim extension = String.Empty

    Dim warnings() As Warning = Nothing

    Dim streamIDs As String() = Nothing

    Dim frmMain As New Form1

    Dim frmRpt As New FrmReport

    Try

    'Dim rptStream As StreamWriter = New StreamWriter("UsingWebBrPrintRpt\rptBackNo.rdlc")

    'Set object data source

    'Me.BindingSource.DataSource = rptData

    'ReportViewer1.RefreshReport()

    rptViewer.ProcessingMode = ProcessingMode.Local

    ''Required since the report is using a custom function to access the external Data

    rptViewer.LocalReport.ExecuteReportInCurrentAppDomain( _

    System.Reflection.Assembly.GetExecutingAssembly().Evidence)

    MessageBox.Show("20", "cPrintPDF")

    'Set local report

    frmRpt.dtMyTableAdapter.Fill(frmRpt.MyDataSet.dtRepTable)

    'Process printing Class

    'Demo_DirectPrinting.Main() -----> even the other class to print without viewing report won't work

    rptViewer.Reset()

    rptViewer.LocalReport.ReportPath = "MyApp1.rptBackNo.rdlc"

    'rptViewer.LocalReport.ReportEmbeddedResource = "MyApp1.rptBackNo.rdlc"

    'Dim list As New List(Of Stream)

    Dim rptDataSource As ReportDataSource = _

    New ReportDataSource("MyDataSet_dtRepTable", frmRpt.MyDataSet.dtRepTable)

    'rptViewer.LocalReport.DataSources.Clear()

    rptViewer.LocalReport.DataSources.Add(rptDataSource)

    rptViewer.RefreshReport()

    frmRpt.Show()

    'Dim txtReader As New StreamReader("MyApp1.rptBackNo.rdlc")

    'rptViewer.LocalReport.LoadReportDefinition(txtReader)

    If File.Exists("C:\ReportMyRpt.pdf") Then File.Delete("C:\ReportMyRpt.pdf")

    'Export to PDF. Get binary content.

    Dim pdfContent As Byte() = rptViewer.LocalReport.Render("PDF", String.Empty, mimeType, encoding, extension, streamIDs, warnings)

    ' ''Create PDF file on disk

    Dim pdfPath As String = "C:\ReportMyRpt.pdf"

    Dim pdfFile As New FileStream(pdfPath, System.IO.FileMode.Create)

    pdfFile.Write(pdfContent, 0, pdfContent.Length)

    pdfFile.Close()

    ' ''Open PDF file

    System.Diagnostics.Process.Start(pdfPath)

    Catch ex As Exception

    MessageBox.Show(ex.Message, ex.Source)

    End Try

    End Sub

     

    What am I doing wrong? i'm using vs.net 2005Pro framworks2.0 with winXP Pro SP2

    Please help i'll approciate it. thanks in advance

    Friday, March 30, 2007 4:59 PM

Answers

  • Try this.... it works for me

     

    Dim deviceInfo As String = ""

    Dim mimeType As String = ""

    Dim encoding As String = ""

    Dim fileNameExtension As String = ""

    Dim streams() As String

    Dim warnings() As Microsoft.Reporting.WinForms.Warning

    Dim bytes() As Byte

    Dim file As System.IO.FileStream

    bytes = Me.ReportViewer1.LocalReport.Render("PDF", deviceInfo, mimeType, encoding, fileNameExtension, streams, warnings)

    file = New System.IO.FileStream("c:\pruebareport.pdf", IO.FileMode.Create)

    file.Write(bytes, 0, bytes.Length)

    file.Close()

    Monday, April 23, 2007 9:50 PM

All replies

  • Try this.... it works for me

     

    Dim deviceInfo As String = ""

    Dim mimeType As String = ""

    Dim encoding As String = ""

    Dim fileNameExtension As String = ""

    Dim streams() As String

    Dim warnings() As Microsoft.Reporting.WinForms.Warning

    Dim bytes() As Byte

    Dim file As System.IO.FileStream

    bytes = Me.ReportViewer1.LocalReport.Render("PDF", deviceInfo, mimeType, encoding, fileNameExtension, streams, warnings)

    file = New System.IO.FileStream("c:\pruebareport.pdf", IO.FileMode.Create)

    file.Write(bytes, 0, bytes.Length)

    file.Close()

    Monday, April 23, 2007 9:50 PM
  • Thanks eocaballero for your time and your replay, i'll try it someday, I spent toooooo much time with it and finally i had to do it on MS Access then print it through vb.net code application.

    thank you.

    AbGoodMan
    Thursday, April 26, 2007 3:47 PM
  • To eocaballero,

    Thank you!  Out of 6 or 7 code samples that I found, yours was not only the simplest, it's the only one that worked.  I just needed to change LocalReport to ServerReport.
    Monday, August 11, 2008 6:48 PM
  • hey eocaballero! thanks a lot for your solution! this was really helpfully! 
    Thursday, August 6, 2009 10:29 PM
  • I searched for hours for a solution like this before stumbling across your post. It works great - thanks!
    Thursday, November 12, 2009 9:57 PM