Retrieve Attached Files from a OneNote Document

All files attached to a Microsoft OneNote document can be retrieved. These files are stored in AttachedFile nodes. The AttachedFile class represents an attached file.

To extract all attached files from a OneNote document, follow these steps:

  1. Use the Document.GetChildNodes method to select all AttachedFile nodes.
  2. Iterate through the resulting node collections.
  3. Extract image bytes array using the AttachedFile.Bytes property.
  4. Save attached file bytes to local space.

The following code example demonstrates how to extract attached files from a OneNote document and save them to local space.

Attach a File to the OneNote Document

To keep a copy of any document or file as part of the OneNote document, developers can attach it to OneNote page. The AttachedFile class represents an attachment file.

To attach a file to a OneNote document, follow these steps:

  1. Use the Document class to generate the OneNote file.
  2. Initialize Page, OutlineElement and Outline classes by passing document object.
  3. Initialize AttachedFile object by passing the document object and file path.
  4. Add attached file node under OutlineElement node.
  5. Save a OneNote document.

Attach File by Passing its Path

The following code example demonstrates how to attach a file to a OneNote document.

Attach File and Set its Icon by Passing Files Path

The following code example demonstrates how to attach a file and also set attach file icon in OneNote document.