Fill word Content Control using C# issue

608 views Asked by At

I have word contains content control like

enter image description here

I want to write many lines on it so in C# I tried many ways :

  1. using EnviromentNewLine .
  2. \n

Example:

                for (int i = 0; i < items.Count; i++)
                {
                    items[i] = string.Format("{0}{1}{2}{3}", (i + 1).ToString(CultureInfo.InvariantCulture), ". ", items[i], "<br />"); 
                }

but I still get the word content control on one line , any idea how to fix it

2

There are 2 answers

0
Dirk Vollmar On BEST ANSWER

The actual problem is, that the plain text content control does not support multiple paragraphs, it is only possibly to insert manual line breaks (which you normally do by pressing Shift+Return). Within the plain text content control, Word automatically replaces Return by Shift+Return as you can see when switching on the formatting symbols.

You basically have two options to solve your issue:

  • Change the content control to a rich text content control. That way you will be able to insert arbitrary content, also new line characters (i.e. multiple actual Word paragraphs)

  • Insert a vertical tab, i.e. ASCII character 11 or \B instead of a new line. This will insert the manual line break required by the plain text content control.

0
Eric On