title: Not sure how to access custom properties set in OpenXML from within VSTO
body: <p>I have a project that has two requirements. One is to create a simple program that adds a custom property to an excel spreadsheet from outside of Excel. The second requirement is to search for, and, if found, extract that custom property from within an application level vsto Excel add-in.</p>
  
  <p>So far I have met the first requirement and have a program that adds some data to the CustomFileProperties of a workbook via OpenXML as follows:</p>
  
  <pre><code>using (var wb = SpreadsheetDocument.Open(WorkbookToRegister, true))
  {
      Log("Finding existing properties...");
      var customPropsPart = wb.CustomFilePropertiesPart;
      if (customPropsPart == null)
      {
          Log("No properties found, adding new part...");
          customPropsPart = wb.AddCustomFilePropertiesPart();
      }
  
      var props = customPropsPart.Properties;
      if (props == null)
      {
          props = new DocumentFormat.OpenXml.CustomProperties.Properties();
          customPropsPart.Properties = props;
      }
  
      foreach (var prop in props.Where(
          prop =&gt; ((CustomDocumentProperty)prop).Name.Value == "niuVersionNumber"))
      {
          Log("Removing existing properties...");
          prop.Remove();
      }
  
      Log("Adding new properties,..");
      var versionProp = new CustomDocumentProperty();
      versionProp.FormatId = Guid.NewGuid().ToString("B");
      propertyGuid = versionProp.FormatId;
      versionProp.Name = "niuVersionNumber";
      propertyName = versionProp.Name;
      versionProp.VTBString = new VTBString(versionNumber);
      props.AppendChild(versionProp);
      var pid = 2;
  
      Log("Assigning IDs to properties,..");
      foreach (var item in props.Cast&lt;CustomDocumentProperty&gt;())
      {
          item.PropertyId = pid++;
      }
      Log("Saving...");
      props.Save();
  }
  </code></pre>
  
  <p>As you can see, the code adds to the file a property named <em>"niuVersionNumber"</em> with a value of <em>versionNumber</em>. This works flawlessly.</p>
  
  <p>The problem is the second requirement. I haven't been able to figure out how to access that custom property from within the VSTO API.</p>
  
  <p>I've searched MSDN and the interwebs, and am aware of the OpenXML and VSTO API documentation, but am having difficulty fully understanding how to get this to work.</p>
  
  <p>Any suggestions or examples would be appreciated!</p>
  
  <p>Regards,</p>
  
  <p>Joe</p>