Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thanks for your request. I think that the following code could be useful for you.
//Open document
Document doc = new Document(@"Test064\in.doc");
//Set doc property value
doc.CustomDocumentProperties["SomeField"].Value = "my value";
//update fields in the document (DOCUMENTPROPERTY and DOCUMENTVALUE field will be updated)
doc.Range.UpdateFields();
//Get collection of FiledStart nodes
ArrayList propertyStarts = new ArrayList();
NodeCollection starts = doc.GetChildNodes(NodeType.FieldStart, true);
foreach (FieldStart start in starts)
{
if (start.FieldType == FieldType.FieldDocProperty)
{
propertyStarts.Add(start);
}
}
//For each DOCUMENTPROPERTY Field Start
foreach (FieldStart start in propertyStarts)
{
Node currentNode = start;
Node fieldSeparator = null;
//Remove field code
while (currentNode.NodeType != NodeType.FieldSeparator)
{
currentNode = currentNode.NextSibling;
currentNode.PreviousSibling.Remove();
}
fieldSeparator = currentNode;
//Move to Field End
while (currentNode.NodeType != NodeType.FieldEnd)
{
currentNode = currentNode.NextSibling;
}
//Remove field separator
fieldSeparator.Remove();
//Romove field end
currentNode.Remove();
}
//Save document
doc.Save(@"Test064\out.doc");
Best regards.