Document Services Add-In

A Document Services add-in can be created to perform actions when a Document Services batch gets executed. There are two types of operation: a batch operation that provides access to all the documents inside a batch and a document operation that let a user perform actions on a specific document.

Document Services add-ins are available for Content Manager and Template Manager applications.

How to build

Follow these steps to create a Form Data Provider add-in:

  1. Create a new class library using Visual Studio that targets the .NET Framework version used by the Portal that will host the add-in.
  2. Add the Xpertdoc.DocumentServices.AddIn NuGet package to the project.
  3. Locate the classes BatchOperationAddin and DocumentOperationAddin that were added by the Nuget package install script.
  4. Update the method Execute in either one or both operation classes with the code that will perform your actions on the documents. This code can reference the passed in context.MetadataInfo property if the actions outcome depend on specific runtime values.

Here's a sample Execute implementation:

/// <summary>
/// Executes the specified context.
/// </summary>
/// <param name="context">The context.</param>
/// <returns>The result of the operation.</returns>
public IBatchOperationResult Execute(IBatchOperationContext context)
  if (context == null)
    throw new ArgumentNullException(nameof(context));

  return new SimpleBatchOperationResult
    OutputContent = new byte[] { 0, 1, 2, 3, 4, 5 },
    OutputName = "",
    OutputType = DocumentType.Other,

Parameters can be passed to the add-in via the MetadataInfo property. To define custom properties, add them to the BatchOperationMetadata or the DocumentOperationMetadata class.

Office Application Version Add-Ins

An Office Application specific Document Services add-in can be created by using one of the variants of the Document Services NuGet package:

  • Xpertdoc.DocumentServices.AddIn.Word
  • Xpertdoc.DocumentServices.AddIn.Excel
  • Xpertdoc.DocumentServices.AddIn.PowerPoint

Using one of those packages, you can get access to office document instances via the context property:

public IWordDocumentOperationResult Execute(IWordDocumentOperationContext context)
  context.WordDocument.Application.Selection.TypeText(@"New text");
  return new SimpleWordDocumentOperationResult()
    OutputName = context.WordDocumentName,
    OutputType = context.WordDocumentType,

Word, Excel and PowerPoint are available depending on the selected NuGet package.

Template Manager Operation (DOPA)

A Document Services add-in can be also used inside the Template Manager application as a document output post action (DOPA). In order to create such an add-in, you must use the Xpertdoc.TemplateManager.Operations NuGet package. Here's a sample DOPA add-in that sends a copy of a template execution result to a mail recipient:

public IDocumentOperationResult Execute(IDocumentOperationContext context)
  var message = new MailMessage("[email protected]", "[email protected]");
  message.Subject = "Template Manager Operations (DOPA) Test";
  message.Body = "Here's a copy of the resulting document.";
  using (var ms = new MemoryStream(context.DocumentContent))
    message.Attachments.Add(new Attachment(ms, context.DocumentName));
    var client = new SmtpClient("smtphost");
    client.Credentials = new NetworkCredential("user", "password");

    new Xpertdoc.TemplateManager.Operations.TemplateManagerDocumentOperationResult
      OutputContent = context.DocumentContent,
      OutputName = context.DocumentName,
      OutputType = context.DocumentType

An Office Word version of the NuGet package (Xpertdoc.TemplateManager.Operations.Word) can be used instead if access to a Word office instance is desired.