Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class SurroundingClass
- Shared onenoteApp As Application = New Application()
- Shared ns As XNamespace = Nothing
- Private Shared Sub Main(ByVal args As String())
- GetNamespace()
- Dim notebookId As String = GetObjectId(Nothing, OneNote.HierarchyScope.hsNotebooks, "MyNotebook")
- Dim sectionId As String = GetObjectId(notebookId, OneNote.HierarchyScope.hsSections, "Sample_Section")
- Dim firstPageId As String = GetObjectId(sectionId, OneNote.HierarchyScope.hsPages, "MyPage")
- GetPageContent(firstPageId)
- Console.Read()
- End Sub
- Private Shared Sub GetNamespace()
- Dim xml As String
- onenoteApp.GetHierarchy(Nothing, OneNote.HierarchyScope.hsNotebooks, xml)
- Dim doc = XDocument.Parse(xml)
- ns = doc.Root.Name.[Namespace]
- End Sub
- Private Shared Function GetObjectId(ByVal parentId As String, ByVal scope As OneNote.HierarchyScope, ByVal objectName As String) As String
- Dim xml As String
- onenoteApp.GetHierarchy(parentId, scope, xml)
- Dim doc = XDocument.Parse(xml)
- Dim nodeName = ""
- Select Case scope
- Case (OneNote.HierarchyScope.hsNotebooks)
- nodeName = "Notebook"
- Case (OneNote.HierarchyScope.hsPages)
- nodeName = "Page"
- Case (OneNote.HierarchyScope.hsSections)
- nodeName = "Section"
- Case Else
- Return Nothing
- End Select
- Dim node = doc.Descendants(ns & nodeName).Where(Function(n) n.Attribute("name").Value = objectName).FirstOrDefault()
- Return node.Attribute("ID").Value
- End Function
- Private Shared Function GetPageContent(ByVal pageId As String) As String
- Dim xml As String
- onenoteApp.GetPageContent(pageId, xml, OneNote.PageInfo.piAll)
- Dim doc = XDocument.Parse(xml)
- Dim outLine = doc.Descendants(ns & "Outline").First()
- Dim content = outLine.Descendants(ns & "T").First()
- Dim contentVal As String = content.Value
- content.Value = "modified"
- onenoteApp.UpdatePageContent(doc.ToString())
- Return Nothing
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement