Working with Attachments
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:
- Use the Document.GetChildNodes method to select all AttachedFile nodes.
- Iterate through the resulting node collections.
- Extract image bytes array using the AttachedFile.Bytes property.
- Save the attached file bytes to the 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 the OneNote page. The AttachedFile class represents an attachment file.
To attach a file to a OneNote document, follow these steps:
- Use the Document class to generate the OneNote file.
- Initialize Page, OutlineElement and Outline classes by passing document object.
- Initialize AttachedFile object by passing the document object and file path.
- Add attached file node under the OutlineElement node.
- 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 the OneNote document.