是否可以将.RDL文件构建到.EXE中进行部署?

时间:2014-06-06 14:21:07

标签: vb.net reportbuilder3.0 report-viewer2012

我有一些.RDL报告我在(VB)Windows窗体应用程序中运行。

我想将其作为单个.EXE文件分发。

是否可以将.RDL文件构建到.EXE?

有一个名为LocalReport.ReportEmbeddedResource的美味属性,但这并不会将.RDL构建到最终文件中。

2 个答案:

答案 0 :(得分:0)

是。 LocalReport.LoadReportDefinition(TextReader)方法可以接受流。您可以使用StringReader从资源或代码中嵌入的常量(字符串)加载报表。

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

示例:

    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

答案 1 :(得分:0)

这是最终解决方案,基于Wil Burton在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

只是为了澄清设置:一个非常简单的(只是一个文本框)。名为aSimpleReport.RDL的.RDL文件被添加为项目资源的“现有文件”。