Class Notebook
Namespace: Aspose.Note
Assembly: Aspose.Note.dll (25.6.0)
Represents an Aspose.Note notebook.
public class Notebook
: INotebookChildNode, IEnumerable<INotebookChildNode>, IEnumerable
{
public void DoSomething()
{
}
}
Inheritance
Implements
INotebookChildNode
,
IEnumerable
Inherited Members
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
Shows how to save notebook.
var notebook = new Notebook();
string dataDir = RunExamples.GetDataDir_NoteBook();
dataDir += "test_out.onetoc2";
notebook.Save(dataDir);
Shows how to save notebook in pdf format.
string dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "Notizbuch Öffnen.onetoc2");
string dataDirNew = dataDir + "ConvertToPDF_out.pdf";
notebook.Save(dataDirNew);
Shows how to save notebook as image.
var dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "Notizbuch Öffnen.onetoc2");
dataDir += "ConvertToImage_out.png";
notebook.Save(dataDir);
Shows how to get all text from a notebook.
string inputFile = "notebook.onetoc2";
string dataDir = RunExamples.GetDataDir_NoteBook();
Notebook rootNotebook = new Notebook(dataDir + inputFile);
IList<RichText> allRichTextNodes = rootNotebook.GetChildNodes<RichText>();
foreach (RichText richTextNode in allRichTextNodes)
{
Console.WriteLine(richTextNode.Text);
}
Shows how to save flattened notebook in pdf format.
var dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "Notizbuch Öffnen.onetoc2");
string dataDir += "ConvertToPDFAsFlattened_out.pdf";
notebook.Save(
dataDir,
new NotebookPdfSaveOptions { Flatten = true }
);
Shows how to iterate through documents of a notebook loading them lazily.
string inputFile = "Notizbuch öffnen.onetoc2";
string dataDir = RunExamples.GetDataDir_NoteBook();
Notebook notebook = new Notebook(dataDir + inputFile);
foreach (var notebookChildNode in notebook.OfType<Document>()) // Notice the capital 'D' for Document type
{
}
Shows how to add new section to a notebook.
var dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "Notizbuch öffnen.onetoc2");
notebook.AppendChild(new Document(dataDir + "Neuer Abschnitt 1.one"));
dataDir += @"\AddChildNode_out.onetoc2";
notebook.Save(dataDir);
Shows how to load notebook from a stream.
string dataDir = RunExamples.GetDataDir_Notebook();
FileStream stream = new FileStream(dataDir + "Notizbuch öffnen.onetoc2", FileMode.Open);
var notebook = new Notebook(stream);
using (FileStream childStream = new FileStream(dataDir + "Aspose.one", FileMode.Open))
{
notebook.LoadChildDocument(childStream);
}
notebook.LoadChildDocument(dataDir + "Sample1.one");
Shows how to an encrypted notebook.
var dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "test.onetoc2", new NotebookLoadOptions() { DeferredLoading = true });
notebook.LoadChildDocument(dataDir + "Aspose.one");
notebook.LoadChildDocument(dataDir + "Locked Pass1.one", new LoadOptions() { DocumentPassword = "pass" });
notebook.LoadChildDocument(dataDir + "Locked Pass2.one", new LoadOptions() { DocumentPassword = "pass2" });
Shows how to save notebook as image with specified options.
string dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "Notizbuch Öffnen.onetoc2");
var notebookSaveOptions = new NotebookImageSaveOptions(SaveFormat.Png);
var documentSaveOptions = notebookSaveOptions.DocumentSaveOptions;
documentSaveOptions.Resolution = 400;
dataDir += "ConvertToImageWithOptions_out.png";
notebook.Save(dataDir, notebookSaveOptions);
Shows how to save flattened notebook as image.
var dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "Notizbuch öffnen.onetoc2");
var notebookSaveOptions = new NotebookImageSaveOptions(SaveFormat.Png)
{
DocumentSaveOptions = new DocumentSaveOptions()
{
Resolution = 400
}
};
notebookSaveOptions.Flatten = true;
dataDir += "ConvertToImageAsFlattenedNotebook_out.png";
notebook.Save(dataDir, notebookSaveOptions);
Shows how to remove a section from a notebook.
string dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "test.onetoc2");
foreach (var child in new List<inotebookchildnode>(notebook))
{
if (child.DisplayName == "Remove Me")
{
notebook.RemoveChild(child);
}
}
dataDir += @"RemoveChildNode_out.onetoc2";
notebook.Save(dataDir);
string dataDir = RunExamples.GetDataDir_NoteBook();
var notebook2 = new Notebook(dataDir + "test.onetoc2");
foreach (var child in new List<inotebookchildnode>(notebook2))
{
if (child.DisplayName == "Remove Me")
{
notebook2.RemoveChild(child);
}
}
dataDir += @"RemoveChildNode_out.onetoc2";
notebook2.Save(dataDir);
Shows how to iterate through preloaded documents of a notebook.
NotebookLoadOptions loadOptions = new NotebookLoadOptions { InstantLoading = true };
string inputFile = "Notizbuch öffnen.onetoc2";
string dataDir = RunExamples.GetDataDir_NoteBook();
Notebook notebook = new Notebook(dataDir + inputFile, loadOptions);
foreach (INotebookChildNode notebookChildNode in notebook.OfType<Document>())
{
}
Shows how to pass through content of a notebook.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
string fileName = "Open Notebook.onetoc2";
try
{
var notebook = new Notebook(dataDir + fileName);
foreach (var notebookChildNode in notebook)
{
Console.WriteLine(notebookChildNode.DisplayName);
if (notebookChildNode is Document)
{
}
else if (notebookChildNode is Notebook)
{
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Constructors
Notebook()
Initializes a new instance of the Aspose.Note.Notebook class.
public Notebook()
{
}
Notebook(string)
Initializes a new instance of the Aspose.Note.Notebook class.Opens an existing OneNote notebook from a file.
public Notebook(string filePath)
{
}
Parameters
filePath
string
The file path.
Notebook(string, NotebookLoadOptions)
Initializes a new instance of the Aspose.Note.Notebook class.Opens an existing OneNote notebook from a file. Allows to specify additional options such as a children loading strategy (“lazy”/instant).
public Notebook(string filePath, NotebookLoadOptions loadOptions)
{
}
Parameters
filePath
string
The file path.
loadOptions
NotebookLoadOptions
The load options.
Notebook(Stream)
Initializes a new instance of the Aspose.Note.Notebook class.Opens an existing OneNote notebook from a stream.
public Notebook(Stream stream)
{
}
Parameters
stream
Stream
The stream.
Notebook(Stream, NotebookLoadOptions)
Initializes a new instance of the Aspose.Note.Notebook class.Opens an existing OneNote notebook from a stream. Allows to specify additional loading options.
public Notebook(Stream stream, NotebookLoadOptions loadOptions)
{
}
Parameters
stream
Stream
The stream.
loadOptions
NotebookLoadOptions
The load options.
Properties
Color
Gets or sets the color.
public Color Color
{
get
{
}
set
{
}
}
Property Value
Count
Gets the number of elements contained in the Aspose.Note.Notebook.
public int Count
{
get;
}
Property Value
DisplayName
Gets or sets the display name.
public string DisplayName
{
get;
set;
}
Property Value
Examples
Shows how to remove a section from a notebook.
string dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "test.onetoc2");
foreach (var child in notebook.Children)
{
if (child.DisplayName == "Remove Me")
{
notebook.RemoveChild(child);
}
}
dataDir += "RemoveChildNode_out.onetoc2";
notebook.Save(dataDir);
FileFormat
Gets file format (OneNote 2010, OneNote Online).
public FileFormat GetFileFormat()
{
return this.FileFormat;
}
Property Value
Guid
Gets the object’s globally unique id.
public Guid Guid
{
get
{
}
}
Property Value
IsHistoryEnabled
Gets or sets a value indicating whether the history is enabled.
public bool IsHistoryEnabled
{
get;
private set;
}
Property Value
this[int]
Gets notebook child node by the given index.
public INotebookChildNode this[int index]
{
get;
}
Property Value
Methods
AppendChild(INotebookChildNode)
Adds the node to the end of the list.
public INotebookChildNode AppendChild(INotebookChildNode newChild)
{
}
Parameters
newChild
INotebookChildNode
The node to add.
Returns
The added node.
GetChildNodes()
Get all child nodes by the node type.
public IList<T1> GetChildNodes<T1>() where T1 : Node
{
}
Returns
A list of child nodes.
Type Parameters
T1
The type of elements in the returned list.
GetEnumerator()
Returns an enumerator that iterates through child nodes of the Aspose.Note.Notebook.
public IEnumerator<notebookchildnode> GetEnumerator()
{
}
Returns
IEnumerator < INotebookChildNode >
A System.Collections.IEnumerator.
LoadChildDocument(string)
Adds a child document node.Opens an existing OneNote document from a file.
public void LoadChildDocument(string filePath)
{
}
Parameters
filePath
string
The file path.
Examples
Shows how to load notebook from a stream.
string dataDir = RunExamples.GetDataDir_NoteBook();
FileStream stream = new FileStream(dataDir + "Notizbuch öffnen.onetoc2", FileMode.Open);
var notebook = new Notebook(stream);
using (FileStream childStream = new FileStream(dataDir + "Aspose.one", FileMode.Open))
{
notebook.LoadChildDocument(childStream);
}
notebook.LoadChildDocument(dataDir + "Sample1.one");
LoadChildDocument(string, LoadOptions)
Adds a child document node.Opens an existing OneNote document from a file. Allows to specify additional load options.
public void LoadChildDocument(
string filePath,
Aspose.Words.LoadOptions loadOptions)
{
}
Parameters
filePath
string
The file path.
loadOptions
LoadOptions
The load options.
LoadChildDocument(Stream)
Adds a child document node.Opens an existing OneNote document from a stream.
public void LoadChildDocument(Stream stream)
{
}
Parameters
stream
Stream
The stream.
Examples
Shows how to load notebook from a stream.
string dataDir = RunExamples.GetDataDir_NoteBook();
FileStream stream = new FileStream(dataDir + "Notizbuch öffnen.onetoc2", FileMode.Open);
var notebook = new Notebook(stream);
using (FileStream childStream = new FileStream(dataDir + "Aspose.one", FileMode.Open))
{
notebook.LoadChildDocument(childStream);
}
notebook.LoadChildDocument(dataDir + "Sample1.one");
LoadChildDocument(Stream, LoadOptions)
Adds a child document node.Opens an existing OneNote document from a stream. Allows to specify additional load options.
public void LoadChildDocument(Stream stream, LoadOptions loadOptions)
{
}
Parameters
stream
Stream
The stream.
loadOptions
LoadOptions
The load options.
LoadChildNotebook(string)
Adds a child notebook node.Opens an existing OneNote notebook from a file.
public void LoadChildNotebook(string filePath)
{
}
Parameters
filePath
string
The file path.
LoadChildNotebook(string, NotebookLoadOptions)
Adds a child notebook node.Opens an existing OneNote notebook from a file. Allows to specify additional load options.
public void LoadChildNotebook(
string filePath,
NotebookLoadOptions loadOptions
)
{
}
Parameters
filePath
string
The file path.
loadOptions
NotebookLoadOptions
The load options.
LoadChildNotebook(Stream)
Adds a child notebook node.Opens an existing OneNote notebook from a stream.
public void LoadChildNotebook(Stream stream)
{
}
Parameters
stream
Stream
The stream.
LoadChildNotebook(Stream, NotebookLoadOptions)
Adds a child notebook node.Opens an existing OneNote notebook from a stream. Allows to specify additional load options.
public void LoadChildNotebook(
Stream stream,
NotebookLoadOptions loadOptions)
{
}
Parameters
stream
Stream
The stream.
loadOptions
NotebookLoadOptions
The load options.
RemoveChild(INotebookChildNode)
Removes the child node.
public INotebookChildNode RemoveChild(INotebookChildNode oldChild)
{
}
Parameters
oldChild
INotebookChildNode
The node to remove.
Returns
The removed node.
Examples
Shows how to access all sections from a notebook.
string inputFile = "notebook.onetoc2";
string dataDir = RunExamples.GetDataDir_NoteBook();
Notebook rootNotebook = new Notebook(dataDir + inputFile);
IList<Document> allDocuments = rootNotebook.GetChildNodes<Document>();
foreach (Document document in allDocuments)
{
Console.WriteLine(document.DisplayName);
}
Shows how to remove a section from a notebook.
var dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "test.onetoc2");
foreach (var child in notebook.Children)
{
if (child.DisplayName == "Remove Me")
{
notebook.RemoveChild(child);
}
}
dataDir += "RemoveChildNode_out.onetoc2";
notebook.Save(dataDir);
Shows how to save a notebook.
string dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "test.onetoc2", new NotebookLoadOptions() { DeferredLoading = false });
notebook.Save(dataDir + "notebook_out.onetoc2", new NotebookOneSaveOptions() { DeferredSaving = true });
if (notebook.Any())
{
var childDocument0 = notebook[0] as Document;
childDocument0.Save(dataDir + "Not Locked_out.one");
var childDocument1 = notebook[1] as Document;
childDocument1.Save(dataDir + "Locked Pass1_out.one", new OneSaveOptions() { DocumentPassword = "pass" });
var childDocument2 = notebook[2] as Document;
childDocument2.Save(dataDir + "Locked Pass2_out.one", new OneSaveOptions() { DocumentPassword = "pass2" });
}
Save(string)
Saves the OneNote document to a file.
public void Save(string fileName)
{
}
Parameters
fileName
string
The full name for the file. If a file with the specified full name already exists, the existing file is overwritten.
Exceptions
IncorrectDocumentStructureException
The document structure violates specification.
UnsupportedSaveFormatException
Requested save format is not supported.
Save(Stream)
Saves the OneNote document to a stream.
public void Save(Stream stream)
{
}
Parameters
stream
Stream
The stream.
Exceptions
IncorrectDocumentStructureException
The document structure violates specification.
UnsupportedSaveFormatException
Requested save format is not supported.
Save(string, SaveFormat)
Saves the OneNote document to a file in the specified format.
public void Save(string fileName, SaveFormat format)
{
}
Parameters
fileName
string
The full name for the file. If a file with the specified full name already exists, the existing file is overwritten.
format
SaveFormat
The format in which to save the document.
Exceptions
IncorrectDocumentStructureException
The document structure violates specification.
UnsupportedSaveFormatException
Requested save format is not supported.
Save(Stream, SaveFormat)
Saves the OneNote document to a stream in the specified format.
public void Save(Stream stream, SaveFormat format)
{
}
Parameters
stream
Stream
The stream.
format
SaveFormat
The format in which to save the document.
Exceptions
IncorrectDocumentStructureException
The document structure violates specification.
UnsupportedSaveFormatException
Requested save format is not supported.
Save(string, NotebookSaveOptions)
Saves the OneNote document to a file using the specified save options.
public void Save(
string fileName,
NotebookSaveOptions options)
{
}
Parameters
fileName
string
The full name for the file. If a file with the specified full name already exists, the existing file is overwritten.
options
NotebookSaveOptions
Specifies the options how the document is saved in file.
Exceptions
IncorrectDocumentStructureException
The document structure violates specification.
UnsupportedSaveFormatException
Requested save format is not supported.
Save(Stream, NotebookSaveOptions)
Saves the OneNote document to a stream using the specified save options.
public void Save(Stream stream, NotebookSaveOptions options)
{
}
Parameters
stream
Stream
The stream.
options
NotebookSaveOptions
Specifies the options how the document is saved.
Exceptions
IncorrectDocumentStructureException
The document structure violates specification.
UnsupportedSaveFormatException
Requested save format is not supported.