Read and edit metadata with GroupDocs.Metadata

GroupDocs.Metadata reads and edits the metadata inside a document — authors, timestamps, EXIF and XMP tags, ID3 audio tags — without touching its visible content. Stripping metadata before a document leaves your organisation is the most common reason to reach for it.

Read document information

GetDocumentInfo gives you the basics without loading the whole metadata tree.

using System;
using GroupDocs.Metadata;
using GroupDocs.Metadata.Common;

using (Metadata metadata = new Metadata("contract.docx"))
{
    IDocumentInfo info = metadata.GetDocumentInfo();

    Console.WriteLine("File format: " + info.FileType.FileFormat);
    Console.WriteLine("Extension: " + info.FileType.Extension);
    Console.WriteLine("MIME type: " + info.FileType.MimeType);
    Console.WriteLine("Pages: " + info.PageCount);
    Console.WriteLine("Size: " + info.Size + " bytes");
    Console.WriteLine("Encrypted: " + info.IsEncrypted);
}

contract.docx is the sample file used in this example. Click here to download it.

File format: WordProcessing
Extension: .docx
MIME type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Pages: 3
Size: 15096 bytes
Encrypted: False

Download full output

Find metadata properties

Properties are searched with a predicate rather than by name, because the same idea is spelled differently in every format. Tags describe what a property means, so Tags.Person.Creator finds the author whether the file calls it Author, Creator or dc:creator.

using System;
using GroupDocs.Metadata;
using GroupDocs.Metadata.Common;
using GroupDocs.Metadata.Tagging;

using (Metadata metadata = new Metadata("contract.docx"))
{
    // Every property tagged as identifying a person
    IEnumerable<MetadataProperty> properties = metadata.FindProperties(
        p => p.Tags.Contains(Tags.Person.Creator));

    foreach (MetadataProperty property in properties)
    {
        Console.WriteLine(property.Name + " = " + property.Value);
    }
}

contract.docx is the sample file used in this example. Click here to download it.

Author = Dana Whitfield
dc:creator = Dana Whitfield

Download full output

Strip metadata before sharing

Sanitize removes every metadata property the format allows to be removed. This is the sanitising step to run before publishing a document externally.

using System;
using GroupDocs.Metadata;

using (Metadata metadata = new Metadata("contract.docx"))
{
    int removed = metadata.Sanitize();
    Console.WriteLine("Properties removed: " + removed);

    metadata.Save("metadata-sanitize.docx");
}

contract.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 15 KB)

Download full output

Learn more

GroupDocs.Metadata also adds and updates properties, removes only the properties matching a predicate, and works with format-specific standards — EXIF, XMP and IPTC in images, ID3 and APE in audio, and the built-in and custom property sets of Office documents.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.