---
title: "Remove hidden data from Office files in C#"
url: https://recursiveai.org/onedocument/cookbook/remove-hidden-office-data/
description: "The defaults remove author details, comments and hidden text, and accept tracked changes."
version: "1.0.0"
---

The defaults remove author details, comments and hidden text, and accept tracked changes.

```shell
dotnet add package RecursiveAI.OneDocument.All
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneDocument;
Office.Sanitize("internal.docx", "clean.docx");
```

Writes `clean.docx`; the snippet prints nothing.

Unzip [the example](https://recursiveai.org/onedocument/cookbook/remove-hidden-office-data/remove-hidden-office-data.zip), then `dotnet run`.

## Full program

The included `internal.docx` contains visible text “Public project summary.”, hidden text “Internal note: budget pending.”, creator “Alex Example” and title “Internal draft”.

```csharp
using RecursiveAI.OneDocument;

var before = Office.Inspect("internal.docx");
var report = Office.Sanitize("internal.docx", "clean.docx");
Console.WriteLine($"Findings before: {before.Findings.Count}");
Console.WriteLine($"Findings after: {report.After.Findings.Count}");
Console.WriteLine($"Wrote: clean.docx ({report.OutputFormat})");
foreach (var item in report.NotRemoved)
    Console.WriteLine($"Kept: {item.Code}: {item.Reason}");
```

`dotnet run` prints:

```text
Findings before: 3
Findings after: 0
Wrote: clean.docx (Docx)
```

If the built-in reinspection fails, `SanitizeVerificationException` is thrown and the destination is not written. Sanitizing has not been independently audited.

## Variations

### Remove document properties only

At version 1.0.0, `Office.Sanitize` uses the default categories; use the lower-level `Sanitizer.Sanitize` to select `Properties` without removing hidden text. This writes `properties-only.docx` and prints the remaining finding’s category.

```csharp
using RecursiveAI.OneDocument;
using RecursiveAI.OneDocument.Inspection;

var report = Sanitizer.Sanitize("internal.docx",
    "properties-only.docx", SanitizeOptions.Only(
        InspectionCategory.Properties));
foreach (var finding in report.After.Findings)
    Console.WriteLine(finding.Category);
```

Output:

```text
HiddenText
```

## Related recipes

- [Remove VBA macros from Excel and Word in C#](https://recursiveai.org/onedocument/cookbook/remove-vba-macros/)
- [Redact a Word document in C#](https://recursiveai.org/onedocument/cookbook/redact-word-document/)

## The short answer

Use `Office.Inspect` to see hidden-data findings, then `Office.Sanitize(input, output)` to remove the default categories into a new file. The full program also reads the report’s after-inspection and any items that were kept. Sanitizing is broader than clearing an author property, but it is not a guarantee that every possible secret has been found.

The example’s three findings are its creator, title and hidden text. The default operation removes them while leaving the visible paragraph.

## How do I remove metadata from documents?

For document properties only, use `Sanitizer.Sanitize` with `SanitizeOptions.Only(InspectionCategory.Properties)`, as in the variation. The category includes core properties such as creator and title, extended properties such as company and manager, and custom properties. It also covers certain application-specific values described in the [sanitizer documentation](https://recursiveai.org/onedocument/docs/sanitize/).

For a broader pre-sharing cleanup, the defaults include comments, revisions, personal information, custom XML, headers and footers, and hidden text, among other categories. Word revisions are accepted, not rejected. That is an editorial decision: inserted text becomes ordinary content and deleted text is discarded. Select only the categories you intend to change, and keep the original file.

`SanitizeOptions.Everything` adds removable categories outside the defaults, including macros and external links. It does not turn report-only categories into removable ones. Look at each category’s status and the `NotRemoved` entries with their reasons. `PartlyRemoved` means selected content remains with an explanation; it is not equivalent to an empty category.

The same API handles Word, Excel and PowerPoint through their registered providers. The example installs the `.All` metapackage to include those providers. Legacy binary, RTF and 2003 XML inputs are converted through the document model and written as OOXML; use `OutputFormat` to choose the correct extension. Encrypted inputs are decrypted with the supplied context and written unencrypted.

## How do I remove hidden metadata from a Word document?

Inspect more than file properties. A DOCX can also retain reviewer names, revision records, comments, hidden runs and custom XML. Microsoft’s [Document Inspector guidance](https://support.microsoft.com/en-us/office/collab-files/remove-hidden-data-and-personal-information-by-inspecting-documents-presentations-or-workbooks) lists these as distinct kinds of hidden data and recommends working on a copy. Deleting only the creator property does not address the other categories.

OneDocument reopens the written bytes and inspects selected categories before replacing the destination. Findings must either be gone or explained by kept items. This check uses the library’s own inspection code; it is not an independent audit or a search for arbitrary sensitive meaning in visible text.

The published coverage excludes metadata inside embedded pictures, including EXIF, and the contents of embedded documents. White or tiny text and objects covered by other objects are not covered. ODF inspection is not supported at this release. Malformed XML parts are noted rather than inspected as normal content. A tracked change in a Word glossary document is found but kept.

Excel has additional consequences: hidden rows and columns are cleared rather than deleted, and hidden sheets and names are kept when references require them. Formulas depending on cleared cells can change on recalculation. For sensitive visible text, use a separate redaction operation rather than relying on metadata removal.
