Class Extensions
- Namespace
- LinqToOneNote
- Assembly
- LinqToOneNote.dll
A static class containing extension methods for the IOneNoteItem object.
public static class Extensions
- Inheritance
-
Extensions
- Inherited Members
Fields
DefaultRelativePathSeparator
The default separator used in GetRelativePath(IOneNoteItem, bool, string).
public const string DefaultRelativePathSeparator = "\\"
Field Value
Methods
Close(Notebook, bool)
Causes OneNote to synchronizes any offline files with the notebook, if necessary, and then closes the specified
notebook. After the method returns, the notebook no longer appears in the list of open notebooks in the OneNote user interface (UI).
public static void Close(this Notebook notebook, bool force = false)
Parameters
notebookNotebookThe specified OneNote notebook.
forcebooltrue to close the notebook, even if there are changes in the notebook that OneNote cannot sync before closing; otherwise, false.
CreateNotebook(Root, string, OpenMode)
Creates a notebook with a title equal to name located in the directory. If directory is
null, the default notebook location is used.
public static Notebook CreateNotebook(this Root root, string name, OpenMode openMode = OpenMode.None)
Parameters
rootRootnamestringThe name of the new notebook.
openModeOpenModeWhether to open the newly created notebook in OneNote immediately.
Returns
Remarks
This method also adds the created notebook to the Notebooks collection.
Exceptions
- ArgumentException
Thrown if the
nameis not valid for a notebook.- IOException
Thrown if the specified
directoryis not null and does not exist.
- See Also
-
IsValidName<THierarchyItem>(string)
CreateNotebook(Root, string, string, OpenMode)
Creates a notebook with a title equal to name located in the directory. If directory is
null, the default notebook location is used.
public static Notebook CreateNotebook(this Root root, string name, string directory = null, OpenMode openMode = OpenMode.None)
Parameters
rootRootnamestringThe name of the new notebook.
directorystringThe directory to create the notebook
openModeOpenModeWhether to open the newly created notebook in OneNote immediately.
Returns
Remarks
This method also adds the created notebook to the Notebooks collection.
Exceptions
- ArgumentException
Thrown if the
nameis not valid for a notebook.- IOException
Thrown if the specified
directoryis not null and does not exist.
- See Also
-
IsValidName<THierarchyItem>(string)
CreatePage(Section, string, OpenMode)
Creates a page with a title equal to name located in the specified section.
public static Page CreatePage(this Section parent, string name = "", OpenMode openMode = OpenMode.None)
Parameters
parentSectionnamestringThe title of the page.
openModeOpenModeSpecifies whether/how the newly created page should be opened.
Returns
Exceptions
- ArgumentNullException
Thrown if the parameter
sectionis null- ArgumentException
Thrown if the
sectionis in a recycle bin
CreateSection(INotebookOrSectionGroup, string, OpenMode)
Creates a section with a title equal to name located in the specified parent.
public static Section CreateSection(this INotebookOrSectionGroup parent, string name, OpenMode openMode = OpenMode.None)
Parameters
parentINotebookOrSectionGroupThe hierarchy item to create the section in.
namestringThe name of the new section.
openModeOpenModeWhether to open the newly created section in OneNote immediately.
Returns
Exceptions
- ArgumentException
Thrown if the
nameis not a valid section name.
- See Also
-
IsValidName<THierarchyItem>(string)
CreateSectionGroup(INotebookOrSectionGroup, string, OpenMode)
Creates a section group with a title equal to name located in the specified parent.
public static SectionGroup CreateSectionGroup(this INotebookOrSectionGroup parent, string name, OpenMode openMode = OpenMode.None)
Parameters
parentINotebookOrSectionGroupThe hierarchy item to create the section group in.
namestringThe name of the new section group.
openModeOpenModeWhether to open the newly created section group in OneNote immediately.
Returns
- SectionGroup
The newly created section group.
Exceptions
- ArgumentException
Thrown if the
nameis not a valid section group name.
- See Also
-
IsValidName<THierarchyItem>(string)
Delete(IDeletable, DateTime, bool)
Deletes the hierarchy item from the OneNote notebook hierarchy. For notebooks use
CloseNotebook(Notebook, bool). Does nothing if the item is already in the Recycle Bin.
public static void Delete(this IDeletable item, DateTime dateExpectedLastModified = default, bool deletePermanently = false)
Parameters
itemIDeletableThe item to be deleted
dateExpectedLastModifiedDateTimeThe date and time that you think the object you want to delete was last modified. If you pass a non-zero value for this parameter, OneNote proceeds with the update only if the value you pass matches the actual date and time the object was last modified. Passing a value for this parameter helps prevent accidentally overwriting edits users made since the last time the object was modified.
deletePermanentlybooltrue to permanently delete the item; false to move the item into the OneNote recycle bin for the corresponding Notebook (the default). If the Notebook is in OneNote 2007 format, no recycle bin exists, so the content is permanently deleted.
DeleteOrClose(IOneNoteItem, DateTime, bool, bool)
Extension that method that combines DeleteItem(IDeletable, DateTime, bool) and CloseNotebook(Notebook, bool), i.e. deletes the item if it is a IDeletable or closes it if it is a notebook.
public static void DeleteOrClose(this IOneNoteItem item, DateTime dateExpectedLastModified = default, bool deletePermanently = false, bool force = false)
Parameters
itemIOneNoteItemThe item to be deleted or closed if it is a notebook
dateExpectedLastModifiedDateTime- The date and time that you think the object you want to delete was last modified. If you pass a non-zero value for this parameter, OneNote proceeds with the update only if the value you pass matches the actual date and time the object was last modified. Passing a value for this parameter helps prevent accidentally overwriting edits users made since the last time the object was modified.
deletePermanentlybool- true to permanently delete the item; false to move the item into the OneNote recycle bin for the corresponding Notebook (the default). If the Notebook is in OneNote 2007 format, no recycle bin exists, so the content is permanently deleted.
forcebool- true to close the notebook, even if there are changes in the notebook that OneNote cannot sync before closing; otherwise, false.
Exceptions
- See Also
GetPageContent(Page)
Gets the content of the specified page.
public static string GetPageContent(this Page page)
Parameters
pagePageThe page to retrieve content from.
Returns
GetRecycleBin(Notebook, out SectionGroup)
Get the recycle bin section group for the specified notebook if it exists.
public static bool GetRecycleBin(this Notebook notebook, out SectionGroup sectionGroup)
Parameters
notebookNotebookThe notebook to get the recycle bin of.
sectionGroupSectionGroupWhen this method returns,
sectionGroupcontains the recycle bin of thenotebookif it was found; otherwise, null.
Returns
GetRelativePath(IOneNoteItem, bool, string)
Returns the relative path of the specified item within its Notebook.
public static string GetRelativePath(this IOneNoteItem item, bool useNotebookDisplayName = true, string separator = "\\")
Parameters
itemIOneNoteItemThe item to get the relative path of.
useNotebookDisplayNameboolWhether to use the notebook's DisplayName or Name when getting the path.
separatorstringThe separator to use between path components.
Returns
IsInRecycleBin(IOneNoteItem)
Returns a value that indicates whether the item is in or is a recycle bin.
public static bool IsInRecycleBin(this IOneNoteItem item)
Parameters
itemIOneNoteItemThe OneNote item to check.
Returns
Remarks
Checks whether the item is a recycle bin section group,
a deleted page, a deleted section, or the deleted pages
section within a recycle bin.
- See Also
ItemEquals(IOneNoteItem, IOneNoteItem)
Checks if two IOneNoteItems represent the same item in OneNote by comparing their Id.
public static bool ItemEquals(this IOneNoteItem left, IOneNoteItem right)
Parameters
leftIOneNoteItemThe first item to compare.
rightIOneNoteItemThe second item to compare.
Returns
- See Also
Open(INavigable)
Opens the item in OneNote. If there is no OneNote window a new one is created, else whether a new window is created is
defined by newWindow.
public static void Open(this INavigable item)
Parameters
itemINavigableThe item to open
Rename(IOneNoteItem, string)
Renames the specified item to newName.
For notebooks, this renames its display name, not the folder on disk.
public static void Rename(this IOneNoteItem item, string newName)
Parameters
itemIOneNoteItemThe item to be renamed
newNamestringThe new name of the item
Exceptions
- ArgumentException
Thrown if the
itemis in the Recycle Bin.
Thrown ifnewNameis invalid for theitemtype. See IsValidName<THierarchyItem>(string).- ArgumentNullException
Thrown if
itemis null.
Sync(INavigable)
Forces OneNote to sync the item.
public static void Sync(this INavigable item)
Parameters
itemINavigable- The item to open
TryGetNotebook(IOneNoteItem, out Notebook)
Attempts to get the Notebook that contains the specified item.
This can be false if the item is in a open section or a its a hierarchy is only partially queried.
public static bool TryGetNotebook(this IOneNoteItem item, out Notebook notebook)
Parameters
itemIOneNoteItemThe item to get the notebook of.
notebookNotebookWhen this method returns,
notebookcontains the notebook of theitemif it was found; otherwise, null.