title: Trying to insert a digital signature line in a docx file
body: <p>I'm trying to insert a digital signature line in an openxml (docx) version of a word document. I don't get any errors but I realize I might be missing a step. Here's my code. It's a windows forms application. Can some one tell me how to properly append a digital signature line to a Run instance? The //S// serves as a marker where we want to insert the digital signature line. It's easy to find with a foreach statement.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Windows.Forms;
  using DocumentFormat.OpenXml.Packaging;
  using DocumentFormat.OpenXml.Vml.Office;
  using DocumentFormat.OpenXml.Wordprocessing;
  
  namespace KeywordSearch
  {
      public partial class Form1 : Form
      {
          FileInfo[] tempfiles;
          List&lt;FileInfo&gt; files = new List&lt;FileInfo&gt;();
  
          public Form1()
          {
              InitializeComponent();
          }
  
          private void btnClose_Click(object sender, EventArgs e)
          {
              Close();
          }
  
          private void btnSearch_Click(object sender, EventArgs e)
          {
              string fileName = txtPath.Text;
              using (WordprocessingDocument doc =
              WordprocessingDocument.Open(fileName, false))
              {
                  foreach (Text t in doc.MainDocumentPart.Document.Body.Descendants&lt;Text&gt;())
                  {
                      if (t.Text == "//S//")
                      {
                          lbxResults.Items.Add(t.Text);
  
                          Run r = (Run)t.Parent;
  
                          SignatureLine signature = new SignatureLine();
                          signature.SuggestedSigner = "Pete Smith";
                          signature.SuggestedSigner2 = "Programmer";
                          signature.SuggestedSignerEmail = "pete.smith@navy.mil";
                          signature.SigningInstructions = "Please sign";
                          signature.ShowSignDate = true;
                          signature.AllowComments = true;
  
  
  
                          r.AppendChild&lt;SignatureLine&gt;(signature);
                      }
                  }
              }
  
              lbxResults.Items.Add("Completed adding digital signature liens.");
          }
      private void btnBrowse_Click(object sender, EventArgs e)
      {
          openFileDialog1.ShowDialog();
  
          txtPath.Text = openFileDialog1.FileName;
      }
  }
  </code></pre>
  
  <p>}</p>