OneDocument is a free, open-source C# document library from Recursive AI, licensed under MIT or Apache-2.0. NuGet · GitHub
dotnet new console dotnet add package RecursiveAI.OneDocument.Documents --version 1.0.0
OneDocument.Documents 1.0.0 targets .NET 10 (net10.0) only.
using RecursiveAI.OneDocument; using RecursiveAI.OneDocument.Documents; using (var draft = Document.Create()) { draft.Body.AddParagraph("Gate inspection: pending"); draft.SaveAs("draft.docx"); } using (var doc = Document.Open("draft.docx")) { doc.Replace("pending", "complete"); doc.SaveAs("updated.docx"); } Console.WriteLine(Office.ExtractText("draft.docx").Trim()); Console.WriteLine(Office.ExtractText("updated.docx").Trim());
Gate inspection: pending Gate inspection: complete
The program creates a draft, edits a copy, and reads both saved files back as text. It does not start Word or use the rendering package.
Which OneDocument package handles DOCX?
| Package | Choose it when |
|---|---|
| Documents | You want to read, create, or edit a DOCX through paragraphs and styles. Start here for the example above. |
| Core | You need shared APIs or direct access to file containers and XML. Documents already brings in Core. |
| Schema | You want typed views of XML elements such as WordprocessingML, rather than the high-level document model. Documents already brings in Schema. |
| Rendering | You need to lay out pages or export a PDF or page image. |
DOCX stores document parts such as the main text and styles in a ZIP container. Opening or editing those parts isn’t the same as laying out pages. If you only need the words or want to change a heading and save another DOCX, you don’t need a renderer. See the package list at 1.0.0 for the full split.
Pick the API by what you need back
- Text or structure from an existing file:
Office.ExtractTextgives you text for an index or preview.Document.Opengives you structure, so you can distinguish a heading by its style instead of guessing from its text. See read a Word document. - A new Word file: start with
Document.Createfor content you generate in code. Start with an existing template when the document already has the styles and structure you want. See create a Word document for the blank-file path. - An edited Word file: use
Document.OpenandSaveAsto write a separate copy while you check the result. Use the find and replace recipe to handle phrases split across differently formatted runs and inspect any matches left unchanged.