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
| Property | Type | Access | Description |
|---|---|---|---|
FileName | str | None | Read | The original filename of the attachment as stored in the OneNote file (e.g. "report.xlsx"). None when the filename metadata is absent. |
Bytes | bytes | Read | Raw binary content of the attached file. Defaults to b"" when the attachment data could not be read. |
Tags | list[NoteTag] | Read | OneNote tags attached to this file node. |
Inherited from CompositeNode / Node
| Property | Type | Description |
|---|---|---|
FirstChild | Node | None | First child node |
LastChild | Node | None | Last child node |
ParentNode | Node | None | Containing OutlineElement |
Document | Document | None | Root document |
NodeType | NodeType | NodeType.AttachedFile |
Notes
- Read-only content:
BytesandFileNameare 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
AttachedFilenodes 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
.onefile,Bytesreturnsb"".
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
- CompositeNode: parent class
- NoteTag: tags on an attachment
- OutlineElement: container for
AttachedFile - Developer Guide