vb.netreportbuilder3.0report-viewer2012

Is it possible to build .RDL file into an .EXE for deployment?


I have a few .RDL reports that I run in a (VB) Windows Forms application.

I'd like to distribute it as a single .EXE file.

Is it possible to build the .RDL files into the .EXE?

There's this tasty property called LocalReport.ReportEmbeddedResource, but this doesn't build the .RDL into the final file.


Solution

  • Yes. The LocalReport.LoadReportDefinition(TextReader) method can accept a stream. You can use a StringReader to load the report from your resources or from a constant (string) embedded in your code.

    http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.localreport.loadreportdefinition(v=vs.100).aspx

    http://msdn.microsoft.com/en-us/library/system.io.stringreader(v=vs.110).aspx

    Example:

        Const rdl As String = "<Report>" & _
                 "  <DataSets>" & _
                 "      <DataSet Name=""IrrelevantToThisExample"">" & _
                 "          <Query>" & _
                 "              <DataSourceName>DataTableName</DataSourceName>" & _
                 "              <CommandText>SELECT * FROM sys.Tables</CommandText>" & _
                 "          </Query>" & _
                 "      </DataSet>" & _
                 "  </DataSets>" & _
                 "</Report>"
        'the LocalReport.LoadReportDefinition needs to read the string from a stream
        'Create a string reader to convert the string into a stream
        Using sr As New System.IO.StringReader(rdl)
            MyReportViewer.LocalReport.LoadReportDefinition(sr)
            sr.Close()
        End Using