title: Edit MailMerge via OpenXml
body: <p>I have a <code>.docx</code> which includes a MailMerge, I need to change its source via code (C#). As library I'm using <code>OpenXml</code>. By Opening the docx as a zip file and looking for the paths, I have found that the link of the datasource is stored in two different places: in the <code>word/settings.xml</code> and in the <code>word/_rels/settings.xml.rels</code>.</p>
  
  <p>To replace the fisrt:</p>
  
  <pre><code>var template = new MemoryStream(myDocxInByteArray);
  
  using (var doc = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(template, true))
  {
      var s = doc.MainDocumentPart.DocumentSettingsPart.Settings;
      foreach (var els in s.ChildElements)
      {
          if (els is DocumentFormat.OpenXml.Wordprocessing.MailMerge)
          {
              var mm = (DocumentFormat.OpenXml.Wordprocessing.MailMerge)els;
  
              mm.Query.Val = "SELECT * FROM " + myNewPath;
  
              break;
          }
      }
  }
  </code></pre>
  
  <p>This works fine, however when the file is opened Word asks to load the file from the new path but also from the old one, since it is defined in the <code>word/_rels/settings.xml.rels</code>. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"&gt;
      &lt;Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/mailMergeSource" Target="oldPath" TargetMode="External"/&gt;
  &lt;/Relationships&gt;
  </code></pre>
  
  <p>How can I find this object(<code>Relation</code>) in the <code>WordprocessingDocument</code>? Cannot find it...
  Or is there another way to change it?</p>
  
  <p>EDIT:</p>
  
  <p>I created two different empty files with a different source and then opened with the OpenXml Productivity Tool in order to compare them. As I already have seen the differences are in the <code>word/settings.xml</code> and in the <code>word/_rels/settings.xml.rels</code>.</p>