Class Notebook

Class Notebook

Namespace: Aspose.Note
Assembly: Aspose.Note.dll (24.12.0)

Represents an Aspose.Note notebook.

public class Notebook : INotebookChildNode, IEnumerable<inotebookchildnode>, IEnumerable

Inheritance

objectNotebook

Implements

INotebookChildNode, IEnumerable<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.```csharp // The path to the documents directory. string dataDir = RunExamples.GetDataDir_NoteBook();

                                  var notebook = new Notebook();

                                  dataDir = dataDir + "test_out.onetoc2";

                                  // Save the Notebook
                                  notebook.Save(dataDir);

Shows how to save notebook in pdf format.```csharp
// The path to the documents directory.
                                                    string dataDir = RunExamples.GetDataDir_NoteBook();

                                                    // Load a OneNote Notebook
                                                    var notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2");

                                                    dataDir = dataDir + "ConvertToPDF_out.pdf";

                                                    // Save the Notebook
                                                    notebook.Save(dataDir);

Shows how to save notebook as image.```csharp // The path to the documents directory. string dataDir = RunExamples.GetDataDir_NoteBook();

                                           // Load a OneNote Notebook
                                           var notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2");

                                           dataDir = dataDir + "ConvertToImage_out.png";

                                           // Save the Notebook
                                           notebook.Save(dataDir);

Shows how to get all text from a notebook.```csharp
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);
                                                     }</richtext></richtext>

Shows how to save flattened notebook in pdf format.```csharp // The path to the documents directory. string dataDir = RunExamples.GetDataDir_NoteBook();

                                                          // Load a OneNote Notebook
                                                          var notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2");

                                                          // Save the Notebook
                                                          dataDir = dataDir + "ConvertToPDFAsFlattened_out.pdf";
                                                          notebook.Save(
                                                              dataDir,
                                                              new NotebookPdfSaveOptions
                                                              {
                                                                  Flatten = true
                                                              });

Shows how to iterate through documents of a notebook loading them lazily.```csharp
string inputFile = "Notizbuch öffnen.onetoc2";
                                                                                    string dataDir = RunExamples.GetDataDir_NoteBook();

                                                                                    // By default children loading is "lazy".
                                                                                    Notebook notebook = new Notebook(dataDir + inputFile);

                                                                                    foreach (var notebookChildNode in notebook.OfType<document>()) 
                                                                                    {
                                                                                        // Actual loading of the child document happens only here.
                                                                                        // Do something with child document
                                                                                    }</document>

Shows how to add new section to a notebook.```csharp // The path to the documents directory. string dataDir = RunExamples.GetDataDir_NoteBook();

                                                  // Load a OneNote Notebook
                                                  var notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2");

                                                  // Append a new child to the Notebook
                                                  notebook.AppendChild(new Document(dataDir + "Neuer Abschnitt 1.one"));

                                                  dataDir = dataDir + "AddChildNode_out.onetoc2";

                                                  // Save the Notebook
                                                  notebook.Save(dataDir);

Shows how to load notebook from a stream.```csharp
// The path to the documents directory.
                                                    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.```csharp // The path to the documents directory. string 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.```csharp
// The path to the documents directory.
                                                                      string dataDir = RunExamples.GetDataDir_NoteBook();

                                                                      // Load a OneNote Notebook
                                                                      var notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2");

                                                                      var notebookSaveOptions = new NotebookImageSaveOptions(SaveFormat.Png);

                                                                      var documentSaveOptions = notebookSaveOptions.DocumentSaveOptions;

                                                                      documentSaveOptions.Resolution = 400;

                                                                      dataDir = dataDir + "ConvertToImageWithOptions_out.png";

                                                                      // Save the Notebook
                                                                      notebook.Save(dataDir, notebookSaveOptions);

Shows how to save flattened notebook as image.```csharp // The path to the documents directory. string dataDir = RunExamples.GetDataDir_NoteBook();

                                                     // Load a OneNote Notebook
                                                     var notebook = new Notebook(dataDir + "Notizbuch öffnen.onetoc2");

                                                     var notebookSaveOptions = new NotebookImageSaveOptions(SaveFormat.Png);

                                                     var documentSaveOptions = notebookSaveOptions.DocumentSaveOptions;

                                                     documentSaveOptions.Resolution = 400;
                                                     notebookSaveOptions.Flatten = true;

                                                     dataDir = dataDir + "ConvertToImageAsFlattenedNotebook_out.png";

                                                     // Save the Notebook
                                                     notebook.Save(dataDir, notebookSaveOptions);

Shows how to remove a section from a notebook.```csharp
// The path to the documents directory.
                                                         string dataDir = RunExamples.GetDataDir_NoteBook();

                                                         // Load a OneNote Notebook
                                                         var notebook = new Notebook(dataDir + "test.onetoc2");

                                                         // Traverse through its child nodes for searching the desired child item
                                                         foreach (var child in new List<inotebookchildnode>(notebook))
                                                         {
                                                             if (child.DisplayName == "Remove Me")
                                                             {
                                                                 // Remove the Child Item from the Notebook
                                                                 notebook.RemoveChild(child);
                                                             }
                                                         }

                                                         dataDir = dataDir + "RemoveChildNode_out.onetoc2";

                                                         // Save the Notebook
                                                         notebook.Save(dataDir);</inotebookchildnode>

Shows how to iterate through preloaded documents of a notebook.```csharp // By default children loading is “lazy”. // Therefore for instant loading has took place, // it is necessary to set the NotebookLoadOptions.InstantLoading flag. NotebookLoadOptions loadOptions = new NotebookLoadOptions { InstantLoading = true };

                                                                      String inputFile = "Notizbuch öffnen.onetoc2";
                                                                      String dataDir = RunExamples.GetDataDir_NoteBook();
                                                                      Notebook notebook = new Notebook(dataDir + inputFile, loadOptions);

                                                                      // All child documents are already loaded.
                                                                      foreach (INotebookChildNode notebookChildNode in notebook.OfType<document>()) 
                                                                      {
                                                                         // Do something with child document
                                                                      }</document>

Shows how to pass through content of a notebook.```csharp
// The path to the documents directory.
                                                           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)
                                                                   {
                                                                       // Do something with child document
                                                                   }
                                                                   else if (notebookChildNode is Notebook)
                                                                   {
                                                                       // Do something with child 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

Color

Count

Gets the number of elements contained in the Aspose.Note.Notebook.

public int Count { get; }

Property Value

int

DisplayName

Gets or sets the display name.

public string DisplayName { get; set; }

Property Value

string

Examples

Shows how to remove a section from a notebook.```csharp // The path to the documents directory. string dataDir = RunExamples.GetDataDir_NoteBook();

                                                     // Load a OneNote Notebook
                                                     var notebook = new Notebook(dataDir + "test.onetoc2");

                                                     // Traverse through its child nodes for searching the desired child item
                                                     foreach (var child in new List<inotebookchildnode>(notebook))
                                                     {
                                                         if (child.DisplayName == "Remove Me")
                                                         {
                                                             // Remove the Child Item from the Notebook
                                                             notebook.RemoveChild(child);
                                                         }
                                                     }

                                                     dataDir = dataDir + "RemoveChildNode_out.onetoc2";

                                                     // Save the Notebook
                                                     notebook.Save(dataDir);</inotebookchildnode>

### <a id="Aspose_Note_Notebook_FileFormat"></a> FileFormat

Gets file format (OneNote 2010, OneNote Online).

```csharp
public FileFormat FileFormat { get; }

Property Value

FileFormat

Guid

Gets the object’s globally unique id.

public Guid Guid { get; }

Property Value

Guid

IsHistoryEnabled

Gets or sets a value indicating whether the history is enabled.

public bool IsHistoryEnabled { get; set; }

Property Value

bool

this[int]

Gets notebook child node by the given index.

public INotebookChildNode this[int index] { get; }

Property Value

INotebookChildNode

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

INotebookChildNode

The added node.

GetChildNodes<t1>()

Get all child nodes by the node type.

public IList<t1> GetChildNodes<t1>() where T1 : Node

Returns

IList<t1>

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<inotebookchildnode> GetEnumerator()

Returns

IEnumerator<INotebookChildNode&gt;

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.```csharp // The path to the documents directory. 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");

### <a id="Aspose_Note_Notebook_LoadChildDocument_System_String_Aspose_Note_LoadOptions_"></a> LoadChildDocument\(string, LoadOptions\)

Adds a child document node.
Opens an existing OneNote document from a file. Allows to specify additional load options.

```csharp
public void LoadChildDocument(string filePath, 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.```csharp // The path to the documents directory. 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");

### <a id="Aspose_Note_Notebook_LoadChildDocument_System_IO_Stream_Aspose_Note_LoadOptions_"></a> LoadChildDocument\(Stream, LoadOptions\)

Adds a child document node.
Opens an existing OneNote document from a stream. Allows to specify additional load options.

```csharp
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

INotebookChildNode

The removed node.

Examples

Shows how to access all sections from a notebook.```csharp 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);
                                                        }</document></document>

Shows how to remove a section from a notebook.```csharp
// The path to the documents directory.
                                                         string dataDir = RunExamples.GetDataDir_NoteBook();

                                                         // Load a OneNote Notebook
                                                         var notebook = new Notebook(dataDir + "test.onetoc2");

                                                         // Traverse through its child nodes for searching the desired child item
                                                         foreach (var child in new List<inotebookchildnode>(notebook))
                                                         {
                                                             if (child.DisplayName == "Remove Me")
                                                             {
                                                                 // Remove the Child Item from the Notebook
                                                                 notebook.RemoveChild(child);
                                                             }
                                                         }

                                                         dataDir = dataDir + "RemoveChildNode_out.onetoc2";

                                                         // Save the Notebook
                                                         notebook.Save(dataDir);</inotebookchildnode>

Shows how to save a notebook.```csharp // The path to the documents directory. 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" });
                                    }

### <a id="Aspose_Note_Notebook_Save_System_String_"></a> Save\(string\)

Saves the OneNote document to a file.

```csharp
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. </t1></t1></inotebookchildnode>