フォーラム: ヘルプ (スレッド #40670)

How to delete existing custom document properties (2019-04-18 22:38 by rene_juhr #82863)

Hi everybody,
I am trying to delete existing custom document properties from word documents... unfortunatly I am stuck with this...

public void DeleteAllProps(string SCurrentDocs)
{
var VWordApp = new NetOffice.WordApi.Application();
var VDoc = VWordApp.Documents.Open(SCurrentDocs);
var VCustomDocProp = (DocumentProperties)VDoc.CustomDocumentProperties;

foreach (var VProp in VCustomDocProp)
{
VProp.Delete();
}

if (VDoc != null)
{
VDoc.Save();
VDoc.Close();
VDoc = null;
}
if (VWordApp != null)
{
VWordApp.Quit();
VWordApp.Dispose();
VWordApp = null;
}
}


After saving the Document the custom document properties are still existing. Reading the properties in another Method was super easy...
Does anyone has a suggestion how to solve this problem?
Thank you!

Re: How to delete existing custom document properties (2019-04-22 19:43 by jozefizso #82869)

You may try to set the VDoc.Saved property to false before saving. Sometimes, Word may not detect the document has changed when custom properties are deleted. By setting Saved to false, you will force MS Word to save the document when VDoc.Save() is called.

Source: https://www.office-forums.com/threads/help-cant-delete-custom-document-property.1859353/
#82863 への返信