首页 > 解决方案 > 为什么 Dev express ReportService 保存类但加载字节数组?

问题描述

创建报表设计器时,如果创建了 ReportStorageWebExtension,则它有 2 个设置数据方法和 1 个获取数据的方法。

Public Overrides Function GetData(ByVal url As String) As Byte()
    ' Returns report layout data stored in a Report Storage using the specified URL. 
    ' This method is called only for valid URLs after the IsValidUrl method is called.

    Return MyBase.GetData(url)
End Function

  Public Overrides Sub SetData(ByVal report As XtraReport, ByVal url As String)
    ' Stores the specified report to a Report Storage using the specified URL. 
    ' This method is called only after the IsValidUrl and CanSetData methods are called.

    MyBase.SetData(report, url)
End Sub

Public Overrides Function SetNewData(ByVal report As XtraReport, ByVal defaultUrl As String) As String
    ' Stores the specified report using a new URL. 
    ' The IsValidUrl and CanSetData methods are never called before this method. 
    ' You can validate and correct the specified URL directly in the SetNewData method implementation 
    ' and return the resulting URL used to save a report in your storage.

    Return MyBase.SetNewData(report, defaultUrl)
End Function

为什么 set data 得到 aXtraReport但得到的数据为byte()

标签: devexpressreport

解决方案


正如 Devexpress 团队在此票证中所解释的那样,它是这样做的,因此您可以在保存之前访问报告属性。保存它们的正确方法是像这样的字节数组(如图所示

Public Overrides Sub SetData(ByVal report As XtraReport, ByVal url As String)
        ' Write a report to the storage under the specified URL.
        Dim row As DataRow = reportsTable.Rows.Find(Integer.Parse(url))
        If row IsNot Nothing Then
            Using ms As New MemoryStream()
                report.SaveLayoutToXml(ms)
                row("LayoutData") = ms.GetBuffer()
            End Using
            reportsTableAdapter.Update(catalogDataSet)
            catalogDataSet.AcceptChanges()
        End If
    End Sub

推荐阅读