第 5 课:将报表定义发布到报表服务器

更新报表定义的最后一步是将其发布回报表服务器。

将报表发布到报表目录

  1. PublishReportDefinition() Program.cs 文件 (Module1.vb for Visual Basic) 中的 方法的代码替换为以下代码:

    private void PublishReportDefinition()  
    {  
        System.Console.WriteLine("Publishing Report Definition");  
    
        string reportPath =  
            "/AdventureWorks 2012 Sample Reports/Company Sales 2012";  
    
        XmlSerializer serializer =  
            new XmlSerializer(typeof(Report));  
    
        using (MemoryStream stream = new MemoryStream())  
        {  
            // Serialize the report into the MemoryStream  
            serializer.Serialize(stream, _report);  
            stream.Position = 0;  
    
            byte[] bytes = stream.ToArray();  
    
            // Update the report on the report server  
            Warning[] warnings =   
                _reportService.SetItemDefinition(reportPath, bytes, null);  
        }  
    }  
    
    Private Sub PublishReportDefinition()  
    
        System.Console.WriteLine("Publishing Report Definition")  
    
        Dim reportPath As String = _  
            "/AdventureWorks 2012 Sample Reports/Company Sales 2012"  
        Dim serializer As XmlSerializer = _  
            New XmlSerializer(GetType(Report))  
    
        Using stream As MemoryStream = New MemoryStream  
    
            'Serialize the report into the MemoryStream  
            serializer.Serialize(stream, m_report)  
            stream.Position = 0  
    
            'Update the report on the report server  
            Dim bytes As Byte() = stream.ToArray  
            Dim warnings As Warning() = _  
                m_reportService.SetItemDefinition(reportPath, bytes, Nothing)  
    
        End Using  
    
    End Sub  
    

下一课

在下一课中,你将编译并运行 SampleRDLSchema 应用程序。 请参阅 第 6 课: (VB-C#) 运行 RDL 架构应用程序

另请参阅

使用从 RDL 架构生成的类更新报表(SSRS 教程)
报表定义语言 (SSRS)