共用方式為


第 5 課:將報表定義發行到報表伺服器

更新報表定義的最後步驟是將報表定義發行回到報表伺服器。

將報表發行到報表目錄

  • 以下列程式碼取代 Program.cs 檔案 (在 Visual Basic 中為 Module1.vb) 中 PublishReportDefinition() 方法的程式碼:

    private void PublishReportDefinition()
    {
        System.Console.WriteLine("Publishing Report Definition");
    
        string reportPath =
            "/AdventureWorks Sample Reports/Company Sales";
    
        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.GetBuffer();
    
            // Update the report on the report server
            Warning[] warnings = 
                _reportService.SetReportDefinition(reportPath, bytes);
        }
    }
    
    Private Sub PublishReportDefinition()
    
        System.Console.WriteLine("Publishing Report Definition")
    
        Dim reportPath As String = _
            "/AdventureWorks Sample Reports/Company Sales"
        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.GetBuffer
            Dim warnings As Warning() = _
                m_reportService.SetReportDefinition(reportPath, _
                                                    bytes)
    
        End Using
    
    End Sub
    

下一課

在下一課,您將編譯並執行 SampleRDLSchema 應用程式。請參閱<第 6 課:執行 RDL 結構描述應用程式 (VB/C#)>。