Lesson 4: Update the Report Definition Programmatically
New: 17 July 2006
Now that the report definition has been loaded from the report server and you have a reference to it using the report field, you need to update the report definition. For this example, you will update the Description property for the report.
To update the report definition
Replace the code for the UpdateReportDefinition() method in the Program.cs file (Module1.vb for Visual Basic) with the following code:
private void UpdateReportDefinition() { System.Console.WriteLine("Updating Report Definition"); // Create a list of the Items Choices for the Report. The // ItemsChoiceType37 enum represents all the properties // available in the report and the ItemsElementName // represents the properties that exist in the current // instance of the report. List<ItemsChoiceType37> _reportItems = new List<ItemsChoiceType37>(_report.ItemsElementName); // Locate the index for the Description property int index = _reportItems.IndexOf( ItemsChoiceType37.Description); System.Console.WriteLine("- Old Description: " + _report.Items[index]); // Update the Description for the Report _report.Items[index] = "New Report Description"; System.Console.WriteLine("- New Description: " + _report.Items[index]); }
Private Sub UpdateReportDefinition() System.Console.WriteLine("Updating Report Definition") 'Create a list of the Items Choices for the Report. The 'ItemsChoiceType37 enum represents all the properties 'available in the report and the ItemsElementName 'represents the properties that exist in the current 'instance of the report. Dim reportItems As List(Of ItemsChoiceType37) = _ New List(Of ItemsChoiceType37)(m_report.ItemsElementName) 'Locate the index for the Description property Dim index As Integer = _ reportItems.IndexOf(ItemsChoiceType37.Description) System.Console.WriteLine("- Old Description: " & _ m_report.Items(index)) 'Update the Description for the Report m_report.Items(index) = "New Report Description" System.Console.WriteLine("- New Description: " & _ m_report.Items(index)) End Sub
Next Lesson
In the next lesson, you will save the updated report definition back to the report server. See Lesson 5: Publish the Report Definition to the Report Server.
See Also
Tasks
Tutorial: Updating Reports Using Classes Generated from the RDL Schema