The engine MailMerge interprets all public properties of objects in an IEnumerable collection as table columns and child tables. Properties of type IEnumerable are automatically instantiated as relations and are used for merge blocks and nested merge blocks.

The Text Control Reporting template designers for Windows Forms, WPF and ASP.NET provide the functionality to load XML excerpt files. The drop-down buttons Select Master Table, Insert Merge Field and Insert Merge Block are pre-filled with items of a specific Database Excerpt XML file that can be loaded programmatically.

Create database excerpt files from assemblies

This XML database file contains table definitions, relations and optionally row excerpts to provide a preview of the report.

We just published the class AssemblySerializer that creates such XML XSD files from a given assembly. All public classes and the public members are exported with the proper name and return type. This way, you can create the templates with the merge fields and blocks from your own business objects encapsulated in an assembly.

The usage is very easy. The class AssemblySerializer has the static method Serialize that accepts an assembly path and returns the database excerpt as an XML string.

Loading...

The GitHub repository comes with 3 projects:

DocumentServer.AssemblySerializer The class AssemblySerializer itself.
TestProject A Windows Forms test project to select an assembly and to visualize the XML file.
myDummyClass A dummy project with two classes and different member types to test the serializer.

In order to test this class, follow these easy steps.

  1. Download the GitHub repository and open the project TestProject - > TestProject.sln.

  2. Compile and start the project.

  3. Click on Serialize to serialize the sample assembly myDummyClass.dll.

    Serialize the assembly
  4. Click on Save XML, choose a file name and location and confirm with Save.

  5. Open the template designer TX Text Control Words. The designers are located in the start menu in the created folder for your TX Text Control installation.

    Start menu
  6. In the ribbon tab Mailings, click on Load XML File from the Data Source drop-down button.

    Load XML
  7. Browse for the XML file that has been saved in step 4 and confirm with Open.

The drop-down buttons Select Master Table, Insert Merge Field and Insert Merge Block are now pre-filled with items from the serialized assembly. All classes are listed as tables and public members are listed as merge fields. If a class contains a reference to another class in the assembly, a data relation is created and listed in the Edit Data Relations button.

XSD and 'xml-msdata': Background Information

The class AssemblySerializer reads an assembly and creates an XML document that contains the schema information. It uses the schema for the XSD annotations added by the DataSet class (urn:schemas-microsoft-com:xml-msdata). The DataSet class has a function called WriteXmlSchema, which creates the XML schema file. The same schema is used for these excerpt files. The Windows SDK also provides a tool called XSD.exe that creates those files, but the relations are missing and the application cannot be deployed.

Therefore, the AssemblySerializer creates the complete XML file programmatically.

Download the sample from GitHub and test it on your own.

GitHub

Download and Fork This Sample on GitHub

We proudly host our sample code on github.com/TextControl.

Please fork and contribute.

Requirements for This Sample

  • Visual Studio 2012 or better
  • TX Text Control .NET Server for ASP.NET (trial sufficient)