title: Create repeating blocks in word document using c#
body: <p>Hello I am automating a word document from a winforms application using c#. The document contains a number of mail merge fields that I fill from my code. This works fine for fixed fields. </p>
  
  <p>However the document contains a few recurring sections that are repeated n times at run time. Can someone tell me how to create a block of some sort that can be inserted multiple times?</p>
  
  <p>I have tried inserting the text between two bookmarks however this messes up the page formatting.</p>
  
  <p>Any advice would be much appreciated.</p>
  
  <p>Edit:</p>
  
  <p>The function below is what I use to merge the data on to the word template. The Dictionary holds the field name in the first string and the content in the second.</p>
  
  <p>The user is given a sample word template with all the field codes in the document and is then able to change the order of the fields and the styling on his own.</p>
  
  <pre><code>public static void CreateBody(Application wApp, Document wDoc, Dictionary&lt;string, string&gt; fieldContent)
      {
          //Loop through fields in document body.
          foreach (Field mergeField in wDoc.Fields)
          {
              //Find mailmerge fields in the Word document body.
              if (mergeField.Type == WdFieldType.wdFieldMergeField)
              {
                  //Get the fieldName from the template file.
                  string fieldText = mergeField.Code.Text;
                  string fieldName = GetFieldName(fieldText);
  
                  if (fieldContent.ContainsKey(fieldName))
                  {
                      mergeField.Select();
                      if (fieldContent[fieldName] != "")
                      {
                          wApp.Selection.TypeText(fieldContent[fieldName]);
                      }
                      else
                      {
                          //If the field has no content remove the field text from the word file.
                          wApp.Selection.TypeText(" ");                            
                      }
                  }
  
              }
          }
  </code></pre>
  
  <p>Now I am looking for a way to repeat a block of mail merge fields in the template and have them be inserted multiple times, once for each record.</p>