In this report, we want to write out some data of one particular customer e.g. customer’s name, company, job title, address etc. Data model used for all examples is exposed here.

Initially, we are creating a report template. Follow the common preparation steps to start building the template from scratch:

  • Open a new blank Word document and enable it for templating
  • Turn on Data Sources and Elements Explorers
  • Define default data source as the Customer class

After that, you should be at the following point:
Inserting Field Element image

In order to move on with design of the template, the next steps ought to be taken:

  • Add a Docentric Field element from Docentric Ribbon tab to the document:
    Inserting Field Element image
  • Define the Value property of the inserted Field element, binding it to the Customer's LastName property

    First, click on the Binding Control of the Value property:
    Inserting Field Element
    Define the Binding Source and the Binding Path properties on the Binding Control of the Value property in such way that the Source property is bound to the default data source and the Path property is bound to the LastName property of the Customer class:
    Inserting Field Element
    The result is following:
    Inserting Field Element

  • We can add another Field element also in another, more efficient way by using Docentric Element Builder

    Activate Element Builder pane by clicking on proper button on the Docentric Ribbon tab:
    Inserting Field Element
    Assume that we want to insert a Field element bound to the Customer's FirstName property. First, position yourself (by mouse click) within the document exactly at the place you want to insert the Field element. In this way the (possible) context of the inserting element is determined and written out in the sub pane Current Selection - this is important, for example, while inserting Field elements within a List element. However, in the sub pane Value Binding, likewise on the Binding Control previously, the Binding Source and the Binding Path properties of the binding of the inserting Docentric element are being set at the same time as the element is being inserted itself. In our case, we cannot choose anything else than default data source as the Source property, and for this Binding Source list of all properties of the Customer class are available to be selected as the Path property.
    Position in the Element Builder pane on the FirstName property and click the right mouse button; pop-up window with buttons for inserting Docentric elements shows up. Select the button Add Field:
    Inserting Field Element
    The result is the same as with earlier inserted Field element bound to the Customer's LastName property:
    Inserting Field Element

  • In a similar way, from the Docentric Ribbon tab or by using the Element Builder, add other Docentric Field elements as well:
    Finished Report Template image

  • Take a look at the finished template (Design Mode view is turned on):
    Finished Report Template image

  • Save the template

For more detailed explanation about field element and data sources look at Creating report templates using MS Word Add-In.



Now when we have a report template saved, we can proceed to generation of the report. Report generation takes place programmatically, from your application that is using (has a reference to) the Docentric Report Engine dll. This code looks like following:


// Getting specific customer
Customer customerDataSource = DataAccess.GetCustomerById(15);

// Instancing report engine, by assigning the data source
DocumentGenerator dg = new DocumentGenerator(customerDataSource);

// Generating report by specifying the report template and the resulting report (as file paths)
dg.GenerateDocument("example1.docx", "example1_output.docx");


It is also possible to invoke the method GenerateDocument with same parameters typed as System.IO.Stream.


Generated report looks like:
Finished Report Template image