AttachedFile — Aspose.Note FOSS for Python API Reference

Class: AttachedFile

Package: aspose.note Import: from aspose.note import AttachedFile Inherits: CompositeNode

AttachedFile represents a binary file that has been embedded inside a OneNote section. It is a child of OutlineElement. The raw file data is available through the Bytes property; the original filename is in FileName. OneNote tags attached to the attachment are exposed via Tags.


Properties

PropertyTypeAccessDescription
FileNamestr | NoneReadThe original filename of the attachment as stored in the OneNote file (e.g. "report.xlsx"). None when the filename metadata is absent.
BytesbytesReadRaw binary content of the attached file. Defaults to b"" when the attachment data could not be read.
Tagslist[NoteTag]ReadOneNote tags attached to this file node.

Inherited from CompositeNode / Node

PropertyTypeDescription
FirstChildNode | NoneFirst child node
LastChildNode | NoneLast child node
ParentNodeNode | NoneContaining OutlineElement
DocumentDocument | NoneRoot document
NodeTypeNodeTypeNodeType.AttachedFile

Notes

  • Read-only content: Bytes and FileName are parsed directly from the MS-ONE binary. There is no API to replace the embedded file data in v26.2.
  • Save: Saving a document that contains AttachedFile nodes to PDF embeds the attachment metadata but not the binary content in the PDF itself.
  • Empty bytes: If the file data block is missing or zero-length in the source .one file, Bytes returns b"".

Usage Example

Extract all attachments to disk

import os
from aspose.note import Document, AttachedFile

doc = Document("MyNotes.one")
output_dir = "attachments"
os.makedirs(output_dir, exist_ok=True)

for af in doc.GetChildNodes(AttachedFile):
    name = af.FileName or "unnamed_attachment"
    dest = os.path.join(output_dir, name)
    with open(dest, "wb") as f:
        f.write(af.Bytes)
    print(f"Saved: {dest}  ({len(af.Bytes)} bytes)")

List attachments with their tags

from aspose.note import Document, AttachedFile

doc = Document("MyNotes.one")
for af in doc.GetChildNodes(AttachedFile):
    tag_labels = [t.label for t in af.Tags if t.label]
    print(f"{af.FileName!r}  tags={tag_labels}  size={len(af.Bytes)}B")

None-Safety

FileName may be None; always provide a fallback name when writing files. Bytes is always bytes (never None), but may be empty (b""). Tags is always a list (may be empty).


See Also