Last active
April 19, 2024 14:36
-
-
Save groupdocs-com-kb/7d145dfcbd76a9665aec12d8cee54b0d to your computer and use it in GitHub Desktop.
Remove Metadata from DOC using C#. For more information, please follow link: https://kb.groupdocs.com/metadata/net/remove-metadata-from-doc-using-csharp/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using GroupDocs.Metadata; | |
using GroupDocs.Metadata.Common; | |
using GroupDocs.Metadata.Tagging; | |
namespace RemoveMetadatafromDOCUsingCSharp | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Set License to avoid the limitations of Metadata library | |
License lic = new License(); | |
lic.SetLicense(@"GroupDocs.Metadata.lic"); | |
using (Metadata metadata = new Metadata("input.doc")) | |
{ | |
// Remove all the properties satisfying the predicate: | |
// property contains the name of the document author OR | |
// it refers to the last editor OR | |
// the property value is a string that contains the substring "John" | |
// (to remove any mentions of John from the detected metadata) | |
var affected = metadata.RemoveProperties( | |
p => p.Tags.Contains(Tags.Person.Creator) || | |
p.Tags.Contains(Tags.Person.Editor) || | |
p.Value.Type == MetadataPropertyType.String | |
&& p.Value.ToString().Contains("John")); | |
Console.WriteLine("Properties removed: {0}", affected); | |
metadata.Save("output.doc"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment