DEV Community

Shahzad Ashraf
Shahzad Ashraf

Posted on

Read Hidden Metadata in DOCX Files with C# .NET

Accessing concealed details within DOCX files is essential for developers creating compliance-focused, document-heavy applications. With the GroupDocs.Metadata Cloud .NET SDK, you can now programmatically extract DOCX metadata using fewer lines of C# code. Whether you're interested in obtaining author information, revision history, timestamps, or custom embedded properties, this Cloud API provides quick, secure, and scalable access to the metadata layer of your Word documents.

The SDK enables smooth integration into any .NET application—be it desktop or web—without requiring Microsoft Office or other large dependencies. It is designed for developers who need precise management over metadata examination for purposes such as audit logging, digital forensics, content categorization, and workflow automation. Simply authenticate, load the DOCX file from cloud storage, and gain immediate access to an extensive set of metadata fields.

Utilizing the C# REST API to retrieve and read metadata from DOCX files makes processes more efficient and enhances transparency in your document workflows. The SDK is crafted for rapidity and adaptability, aiding .NET developers in constructing smarter applications with complete insight into document-level data. Discover how this Cloud .NET SDK can elevate your metadata management skills by reviewing this step-by-step guide and enhance your decision-making from within your current codebase.

The following C# code example demonstrates how this functionality operates in .NET applications:

using GroupDocs.Metadata.Cloud.Sdk.Api;
using GroupDocs.Metadata.Cloud.Sdk.Client;
using GroupDocs.Metadata.Cloud.Sdk.Model;
using GroupDocs.Metadata.Cloud.Sdk.Model.Requests;

class Program
{
    static void Main(string[] args)
    {

        // Step 1: Set up API credentials and initialize configuration
        string MyAppKey = "your-app-key";
        string MyAppSecret = "your-app-secret";
        var configuration = new Configuration(MyAppKey, MyAppSecret);

        // Step 2: Initialize Metadata API for extracting metadata
        var metadataApi = new MetadataApi(configuration);

        // Step 3: Set up the file info
        var fileInfo = new GroupDocs.Metadata.Cloud.Sdk.Model.FileInfo
        {
            // Path of the source DOCX file in the cloud storage
            FilePath = "SampleFiles/source.docx"
        };

        // Step 4: Define extraction options 
        var extractOptions = new ExtractOptions
        {
            FileInfo = fileInfo,
        };

        // Step 5: Create and execute the request to extract metadata
        var extractRequest = new ExtractRequest(extractOptions);
        var response = metadataApi.Extract(extractRequest);

        // Step 6: Print the extracted DOCX metadata
        var innerPK = response.MetadataTree.InnerPackages;
        for (int i = 0; i < innerPK.Count; i++)
        {
            Console.WriteLine($"\nPackage: {innerPK[i].PackageName}");
            var packageProperties = innerPK[i].PackageProperties;
            for (int j = 0; j < packageProperties.Count; j++)
            {
                Console.WriteLine(packageProperties[j].Name + " : "
                                        + packageProperties[j].Value);
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)