# Read and Write OneNote Notebooks

Open OneNote notebooks from a folder, a .onetoc2 file or a .onepkg export, walk section groups and sections, and write notebooks offline.

**Packages**

- [OfficeIMO.OneNote](https://www.nuget.org/packages/OfficeIMO.OneNote) `dotnet add package OfficeIMO.OneNote`

**Works with**

- .NET
- [PowerShell](/docs/pswriteoffice/install/) `Install-Module PSWriteOffice`

**Target frameworks**

netstandard2.0, net8.0, net10.0, net472

**APIs**

- [`OneNoteNotebook`](/api/onenote/officeimo-onenote-onenotenotebook/)
- [`OneNoteNotebookReader`](/api/onenote/officeimo-onenote-onenotenotebookreader/)
- [`OneNotePackageReader`](/api/onenote/officeimo-onenote-onenotepackagereader/)
- [`OneNoteNotebookWriter`](/api/onenote/officeimo-onenote-onenotenotebookwriter/)
- [`OneNotePackageWriter`](/api/onenote/officeimo-onenote-onenotepackagewriter/)
- [`OneNoteSection`](/api/onenote/officeimo-onenote-onenotesection/)
- [`OneNoteSectionGroup`](/api/onenote/officeimo-onenote-onenotesectiongroup/)
- [`OneNoteNotebookReaderOptions`](/api/onenote/officeimo-onenote-onenotenotebookreaderoptions/)
- [`OneNotePage`](/api/onenote/officeimo-onenote-onenotepage/)
- [`OneNoteDiagnostic`](/api/onenote/officeimo-onenote-onenotediagnostic/)
- [`OneNoteParagraph`](/api/onenote/officeimo-onenote-onenoteparagraph/)
- [`OneNoteTextRun`](/api/onenote/officeimo-onenote-onenotetextrun/)

**Cmdlets**

- [`Open-OfficeOneNote`](/api/powershell/open-officeonenote/)
- [`New-OfficeOneNoteNotebookOptions`](/api/powershell/new-officeonenotenotebookoptions/)

**Limits**

.onepkg reading supports single Cabinet archives with uncompressed, MSZIP or LZX folders; Quantum compression and multi-file cabinet sets are not supported. [OfficeIMO.OneNote support matrix](/compatibility/#package-onenote)

**Verified**

Examples compiled against the source on 2026-11-14

**Data**

- [OfficeIMO.OneNote API index](/api/onenote/index.json)
- [PSWriteOffice command catalog](/data/powershell/commands.json)
- [Capability catalog (JSON)](/data/capabilities.json)

A OneNote notebook is a folder with an `Open Notebook.onetoc2` table of contents, `.one` section files and subfolders for section groups. A `.onepkg` file is the same notebook packed into a Cabinet archive. `OneNoteNotebookReader` opens the folder form and `OneNotePackageReader` opens the package; both return a `OneNoteNotebook` with section groups, sections and pages. `OneNoteNotebookWriter` and `OneNotePackageWriter` write them back.

## Open a notebook folder or table of contents

### C#

```csharp
using OfficeIMO.OneNote;

OneNoteNotebook notebook = OneNoteNotebookReader.Read(
    Path.Combine("Work notebook", "Open Notebook.onetoc2"),
    new OneNoteNotebookReaderOptions {
        IncludeRecycleBin = false,
        ContinueOnSectionError = true
    });

Console.WriteLine(notebook.Name);
foreach (OneNoteDiagnostic diagnostic in notebook.Diagnostics) {
    Console.WriteLine(diagnostic);
}
```

### PowerShell

```powershell
$notebook = Open-OfficeOneNote -Path '.\Work notebook\Open Notebook.onetoc2'
$notebook.Sections | Select-Object Name
```

## Walk section groups, sections and pages

### C#

```csharp
using OfficeIMO.OneNote;

OneNoteNotebook notebook = OneNotePackageReader.Read("Work notebook.onepkg");

void PrintGroup(string name, IList<OneNoteSection> sections, IList<OneNoteSectionGroup> groups, int depth) {
    string indent = new string(' ', depth * 2);
    Console.WriteLine($"{indent}[{name}]");
    foreach (OneNoteSection section in sections) {
        Console.WriteLine($"{indent}  {section.Name} ({section.Pages.Count} pages)");
        foreach (OneNotePage page in section.Pages) {
            Console.WriteLine($"{indent}    - {page.Title}");
        }
    }
    foreach (OneNoteSectionGroup group in groups) {
        PrintGroup(group.Name, group.Sections, group.SectionGroups, depth + 1);
    }
}

PrintGroup(notebook.Name, notebook.Sections, notebook.SectionGroups, 0);
```

### PowerShell

```powershell
$options = New-OfficeOneNoteNotebookOptions -IncludeRecycleBin
$notebook = Open-OfficeOneNote -Path '.\Work notebook.onepkg' -Options $options
$notebook.Sections | ForEach-Object { $_.Pages } | Select-Object Title, LastModifiedUtc
```

## List the notebook structure without loading pages

Set `LoadSectionContent = false` to read only the table of contents, which is fast for large notebooks.

### C#

```csharp
using OfficeIMO.OneNote;

OneNoteNotebook notebook = OneNoteNotebookReader.Read(
    Path.Combine("Work notebook", "Open Notebook.onetoc2"),
    new OneNoteNotebookReaderOptions { LoadSectionContent = false });

foreach (OneNoteSection section in notebook.Sections) {
    Console.WriteLine(section.Name);
}
foreach (OneNoteSectionGroup group in notebook.SectionGroups) {
    Console.WriteLine($"{group.Name}/ ({group.Sections.Count} sections)");
}
```

### PowerShell

```powershell
$options = New-OfficeOneNoteNotebookOptions -NoSectionContent
Open-OfficeOneNote -Path '.\Work notebook\Open Notebook.onetoc2' -Options $options
```

## Create a notebook and a .onepkg package

### C#

```csharp
using OfficeIMO.OneNote;

var notebook = new OneNoteNotebook { Name = "Offline notebook" };

var section = OneNoteSection.Create();
section.Name = "Meetings";
var page = new OneNotePage { Title = "Kickoff" };
var paragraph = new OneNoteParagraph();
paragraph.Runs.Add(new OneNoteTextRun { Text = "Agreed scope and timeline." });
page.DirectContent.Add(paragraph);
section.Pages.Add(page);
notebook.Sections.Add(section);

OneNoteNotebookWriter.Write(notebook, "Offline notebook");
OneNotePackageWriter.Write(notebook, "Offline notebook.onepkg");

OneNoteNotebook reopened = OneNotePackageReader.Read("Offline notebook.onepkg");
Console.WriteLine($"{reopened.Name}: {reopened.Sections.Count} section(s)");
```

<!-- PowerForge markdown source sha256:F7D932C949EB980FBE4E555CF9E69AAA0F007F61518F60E957673D4BBEF4DEC8; title=True -->

<!-- PowerForge markdown artifact sha256:84FFDD5693B95B4EAEE43169B93A4D0605653E8E20FCD1EC525A92804000D698 -->
