title: Write word form fields with DocumentFormat.OpenXML SDK
body: <p>I am writing an application which should use DocumentFormat.OpenXML SDK for writing data to form fields in a word template. But I cannot find a property in the document-object of the SDK where the form fields are stored. </p>
  
  <p>I tried this code:</p>
  
  <pre><code>using (WordprocessingDocument document = WordprocessingDocument.Open("Path/To/document.dotx", true))
  {
      document.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
      MainDocumentPart mainPart = document.MainDocumentPart;
  
      var fields = mainPart.Document.Body.Descendants&lt;FormFieldData&gt;();
  
      foreach (var field in fields)
      {
          if (field.GetType() == typeof(FormFieldData))
          {
              if (field.LocalName == "Name")
              {
                  Console.WriteLine("Hi!");
              }   
          }
       }
  }
  </code></pre>
  
  <p>But fields is always null.</p>