Reputation: 657
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.
Upvotes: 0
Views: 1249
Reputation: 657
This was the final solution, based on Wil Burton's reply at http://social.msdn.microsoft.com/Forums/en-US/f7f92d61-2c23-47e7-b2a3-12ee4ed9fa9a/loading-an-embedded-resource
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' This is a simplest-possible self-contained example that works!!
Dim data() As Byte = My.Resources.aSimpleReport
Dim reportStream As New IO.MemoryStream
reportStream.Write(data, 0, data.Length)
reportStream.Position = 0
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.LoadReportDefinition(reportStream)
ReportViewer1.RefreshReport()
End Sub
Just to clarify the setup: a very simple (just a text box) .RDL file called aSimpleReport.RDL was added as "An Existing File" to the project's Resources.
Upvotes: 0
Reputation: 6734
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/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
Upvotes: 0