Reputation: 408
I am creating a OneNote add-in using OneNote interop in C#. I want to create a page with a specific name, but I'm not able to do so. I used Application.GetHierarchy
to get the XML for my notebooks, modified it using LINQ to XML and pushed it to OneNote with Application.UpdateHierarchy
. It just created a new blank page without any title (Untitled page).
string globalXmlInitialStr;
_oneNoteApp.GetHierarchy(null, OneNote.HierarchyScope.hsPages, out globalXmlInitialStr, OneNote.XMLSchema.xs2010);
var globalXml = XDocument.Parse(globalXmlInitialStr);
var parentXMl = (
from elem in globalXml.Descendants(ONE_NS + oneNoteElementToCreateType)
where (string)elem.Attribute("ID") == _oneNoteApp.Windows.CurrentWindow.CurrentSectionId
select elem
).ElementAt(0);
var newPageXml = new XElement(new XNamespace("http://schemas.microsoft.com/office/onenote/2010/onenote") + "Page");
newPageXml.SetAttributeValue("name", name);
_oneNoteApp.UpdateHierarchy(globalXml.ToString(), OneNote.XMLSchema.xs2010);
I also tried using Application.CreatePage
and then using the ID returned by the method to retrieve the XML element and modify the name attribute, without success. It always creates a new untitled blank page. However, I can easily create sections and section groups with specific names by setting XML the name attribute. I am also able to specify the "pageLevel" attribute for a page, so the problem is really specific to the name of the page.
What am I doing wrong?
Upvotes: 1
Views: 62