Redaction replaces sensitive content in the document file, rather than just hiding it on screen.
dotnet add package RecursiveAI.OneDocument.DocumentsRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
client.docx is in the zip, or you can use your own .docx file.
using RecursiveAI.OneDocument.Documents; using RecursiveAI.OneDocument.Redaction; using var doc = Document.Open("client.docx"); var plan = new RedactionPlan(); plan.Matches.Add( RedactionMatch.Literal("Jane Doe")); var report = doc.Redact(plan, "redacted.docx"); Console.WriteLine($"Verified: {report.Verified}");
Verified: TrueUnzip the example, then dotnet run.
client.docx is in the zip. Its body reads “Client: Jane Doe” and “Status: approved”. The full program recreates this input.
The full program
The download’s Program.cs uses the supplied samples:
using RecursiveAI.OneDocument.Documents; using RecursiveAI.OneDocument.Redaction; using (Document sample = Document.Create()) { sample.Body.AddParagraph("Client: Jane Doe"); sample.Body.AddParagraph("Status: approved"); sample.SaveAs("client.docx"); } using Document doc = Document.Open("client.docx"); var plan = new RedactionPlan(); plan.Matches.Add(RedactionMatch.Literal("Jane Doe")); var report = doc.Redact(plan, "redacted.docx"); Console.WriteLine($"Verified: {report.Verified}"); using Document result = Document.Open("redacted.docx"); foreach (Paragraph paragraph in result.Paragraphs) Console.WriteLine(paragraph.Text);
dotnet run prints:
Verified: True Client: ████████ Status: approved
If content survives, the report has Verified = false and lists survivors; do not release that output.
This operation has not been independently audited.
Variations
Match a normal or nonbreaking space
using RecursiveAI.OneDocument.Documents; using RecursiveAI.OneDocument.Redaction; using var doc = Document.Open("client.docx"); var plan = new RedactionPlan(); plan.Matches.Add(RedactionMatch.Pattern("Jane[ \u00A0]Doe")); var report = doc.Redact(plan, "pattern-redacted.docx"); Console.WriteLine($"Verified: {report.Verified}");
Output:
Verified: TrueRelated recipes
The short answer
Create a RedactionPlan, add a literal or pattern match, then call doc.Redact(plan, outputPath). OneDocument writes a new document and searches the written package for the removed content. Check the returned report, including Verified, Survivors and Gaps, before releasing the output. The source file is not changed.
The redaction documentation defines the matching rules and the report. The example on this page replaces the exact string “Jane Doe” in a generated DOCX. It does not identify personal information automatically or decide which information you are allowed to disclose.
Is it possible to redact a Word document?
Yes, for content covered by the redaction plan. The matcher joins runs within each paragraph, so a name split by bold formatting can still match as a single phrase. It also searches other package locations, including comments, notes, headers, footers, properties and hyperlink targets. This is broader than replacing only the visible body text.
Exact characters matter. A normal space is not a nonbreaking space, and a straight apostrophe is not a typographic apostrophe. The variation uses a pattern to accept either kind of space between the two name components. Matches do not span paragraphs or different parts. List the relevant variants or choose a suitably specific pattern for the document’s actual data.
The output path must differ from the source path. Older formats are staged through the document model into OOXML, so redacting a binary DOC is not an in-place binary edit. The report records whether conversion occurred and the output format. Keep the original under its existing access controls, and distribute only the reviewed output.
How do I black out text in a Word document?
The default redaction mark is █, repeated once per removed character. The first touched run keeps its formatting and receives the mark; matched characters in later runs are cut. The example therefore prints eight block characters for “Jane Doe”. The result is replacement content, not a floating black rectangle layered over an unchanged name.
This operation does not perform optical character recognition. A name inside a picture’s pixels is not matched as document text. Pictures need a region-based removal decision. Derived content can also require review: a table of contents, cross-reference result or document-property count may reflect removed content without containing the literal secret. The report exposes documented gaps rather than silently treating them as solved.
Is putting black over text the same as redacting it?
No. Covering a name changes the view; redaction must remove the underlying content. Loughborough University’s guidance defines redaction as permanently deleting or making confidential information inaccessible. Its manual workflow uses PDF, whereas this recipe produces another editable Word document.
A successful Verified result is the library’s check of the written package against your matches, not an independent audit or a judgment that the document is safe to publish. Binary embedded content, pictures and Unicode variants need particular care. Review the gaps and survivors, inspect the result, and apply a disclosure review appropriate to the sensitivity of the file. Black marks alone are not that review.