Create a content control by code

If you're looking to create a Content Control in your resulting document without coding, refer to this Working with tags.

The application exposes ContentControlInfo, ExpressionOptions, SubdocumentOptions, SubtemplateOptions, ImageOptions classes that can be used to control resulting document's content controls dynamically.

Objects

ContentControlInfo

Allows to set the properties of the Content Control in the resulting document. Referenced by all tag's output that support being within a content control.

Properties

The ContentControlInfo class exposes these public properties:

  • string Tag: The tag of the content control

  • string Title: The title of the content control

  • string PlaceholderText: The text displayed when the content control is empty

  • ContentControlStyle Style: The style of the content control. Possible values are Standard, Tags or Hidden

  • ContentControlLockMode LockMode: The lock mode of the content control. Possible values are Edit, Delete or Locked

Code Sample

new ContentControlInfo()
{
    Tag = "The Tag",
    Title = "The Title",
    PlaceholderText = "Type some text here",
    Style = ContentControlStyle.Standard,
    LockMode = ContentControlLockMode.Delete
}

ExpressionOptions

Properties

The ExpressionOptions class exposes these public properties:

  • object Value: The value printed in the resulting document

  • object HyperlinkUrl: Thehyperlink when clicking on the text in the resulting document

  • bool IsCatchingException: Indicating whether to catch any exception raised when unwrapping a value

  • string ExceptionOutputMessage: The text that will be printed in the resulting document if an exception is thrown

  • ExpressionMode: Possible values are Text or ContentControl. Text option should be set if you're dynamically setting a ContentControlInfo
  • ContentControlInfo ContentControlInfo: The content control properties

Code Sample

new ExpressionOptions() 
{
    Value = "The value",
    HyperlinkUrl = "http://xpertdoc.com",
    IsCatchingException = true,
    ExceptionOutputMessage = "Exception message",
    Mode = ExpressionMode.Text,
    ContentControlInfo = new ContentControlInfo()
    {
       Tag = "The Tag",
       Title = "The Title",
       PlaceholderText = "Type some text here",
       Style = ContentControlStyle.Standard,
       LockMode = ContentControlLockMode.Edit
    }
}

SubdocumentOptions

Properties

The SubdocumentOptions class exposes these public properties:

  • object Value: The value representing a file of a valid file type

  • bool IsCatchingException: Indicating whether to catch any exception raised when unwrapping a value
  • SubdocumentMode: Possible values are Merge, MergeLegacy, EmbedDocx, EmbedRtf, EmbedHtml or ContentControl
  • ContentControlInfo ContentControlInfo: The content control properties

Code Sample

new SubdocumentOptions() 
{
    Value = Convert.FromBase64String(documentInBase64String),
    IsCatchingException = true,
    Mode = SubdocumentMode.Merge,
    ContentControlInfo = new ContentControlInfo()
    {
       Tag = "The Tag",
       Title = "The Title",
       PlaceholderText = "Type some text here",
       Style = ContentControlStyle.Standard,
       LockMode = ContentControlLockMode.Edit
    }
}

SubtemplateOptions

Properties

The SubtemplateOptions class exposes these public properties:

  • object Value: The value representing a template

  • SubtemplateExecutionMode ExecutionMode: Possible values are Default, Isolated, Joined
  • bool IsCatchingException: Indicating whether to catch any exception raised when unwrapping a value
  • IDictionary<string, object> PropertySetters: Dictionary of values to pass to the sub template
  • SubtemplateMode Mode: Possible values are Merge, MergeLegacy, EmbedDocx or ContentControl
  • ContentControlInfo ContentControlInfo: The content control properties

Code Sample

Copy
new SubtemplateOptions()
{     Value = templateAsAByteArray,
    ExecutionMode = SubtemplateExecutionMode.Default,
    IsCatchingException = true,
    PropertySetters = new System.Collections.Generic.Dictionary<string, object>{{"XmlData", XmlData}, {"CustomerName", "Xpertdoc"}},    
    Mode = SubtemplateMode.Merge,     
    ContentControlInfo = new ContentControlInfo()
        {       Tag = "The Tag",
                Title = "The Title",       
                PlaceholderText = "Type some text here",
                Style = ContentControlStyle.Standard,       
                LockMode = ContentControlLockMode.Edit    
        }
}
                
                

ImageOptions

Properties

The ImageOptions class exposes these public properties:

  • object Value: The value representing an image

  • object ValueUrl: The URL to an image. If provided, it has priority over the Value
  • object HyperlinkUrl: The hyperlink when clicking on the image in the resulting document

  • ImageResizeMode ResizeMode: Possible values are FixedSize, FixedSizeMaintainAspectRatio, FixedWidth, FixedHeight or VariableSize

  • bool IsCatchingException: Indicating whether to catch any exception raised when unwrapping a value

  • byte[] ExceptionFallbackImage: A byte array of an image that will be printed in the resulting document if an exception is thrown
  • ImageMode Mode: Possible values are Image or ContentControl

  • ContentControlInfo ContentControlInfo: The content control properties

Copy
Image Option Code Sample
new ImageOptions()
 {
     Value = @"C:\Temp\logo.png",
     ValueUrl = null,
     HyperlinkUrl = "http://xpertdoc.com",
     ResizeMode = ImageResizeMode.FixedSize,
     IsCatchingException = true,
     ExceptionFallbackImage = imageAsAByteArray,
    Mode = ImageMode.Image,
    ContentControlInfo = new ContentControlInfo()
     {
         Tag = "The Tag",
         Title = "The Title",
         PlaceholderText = "Type some text here",
         Style = ContentControlStyle.Standard,
        LockMode = ContentControlLockMode.Edit
     )
 }