Hi I developed application to set document properties using open xml sdk following this article
https://msdn.microsoft.com/en-us/library/office/hh674468.aspx
using (var document = WordprocessingDocument.Open(fileName, true))
{
string propertyName = "CO_CUST_NAME";
var cusProps = document.CustomFilePropertiesPart;
if (cusProps != null)
{
var props = cusProps.Properties;
props.Load(cusProps);
if (props != null)
{
propertyName = "CO_CUST_NAME";
var prop = props.Where(p => ((CustomDocumentProperty)p).Name.Value == propertyName).FirstOrDefault();
if (prop != null)
{
var newProp = new CustomDocumentProperty();
newProp.VTLPWSTR = new VTLPWSTR("Vikasitha1");
newProp.FormatId = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}";
newProp.Name = propertyName;
prop.Remove();
props.AppendChild(newProp);
}
propertyName = "CO_DEL_ADDRESS";
prop = props.Where(p => ((CustomDocumentProperty)p).Name.Value == propertyName).FirstOrDefault();
if (prop != null)
{
var newProp = new CustomDocumentProperty();
newProp.VTLPWSTR = new VTLPWSTR("No 50 Colombo");
newProp.FormatId = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}";
newProp.Name = propertyName;
prop.Remove();
props.AppendChild(newProp);
}
int pid = 2;
foreach (CustomDocumentProperty item in props)
{
item.PropertyId = pid++;
}
props.Save();
}
}
}
and it worked fine
except when I open the document fields doesn't fill up automatically it just stays as blank
but when I right click and click on 'Update Field' it shows the values
I need to fill up these fields automatically. How can I do that, I tried several methods but didn't work.