Reports can be serialized to and deserialized from XML files through one of the SaveToXml and LoadFromXml overloads respectively.
Data sources that are referenced by various report elements are not serialized/deserialized automatically when a report is saved or loaded from a file. When a report is saved to a file, the SerializeDataSource event is raised for each data source in the report. The event argument provides a reference to the data source being serialized and expects to receive a name that should identify the data source in the XML file. This event can be raised multiple times for the same data source if a data source is referenced by more than one report item. When a data source is deserialized, the DeserializeDataSource event is raised to allow clients to resolve a data source using the name specified during serialization.
For example, when serializing a DataSet data source, the DataSetName can be used as a name.
Internally the SaveToXml and LoadFromXml methods call the Save and Load protected methods of the Report class to carry out the serialization and deserialization of the report contents. These methods can be overriden in derived report classes to serialize and deserialize custom report contents. For example, the following Report-derived class provides a new PageMargins property and overrides Save and Load in order to handle the serialization/deserialization of this property:
C#
![]() |
---|
class MyReport : Report |
Visual Basic
![]() |
---|
Class MyReport Private _pageMargins As Margins |