The defaults remove author details, comments and hidden text, and accept tracked changes.
dotnet add package RecursiveAI.OneDocument.AllRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneDocument; Office.Sanitize("internal.docx", "clean.docx");
Writes clean.docx; the snippet prints nothing.
Unzip the example, 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”.
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:
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.
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:
HiddenTextRelated recipes
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.
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 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.