MitchT86
Guest
|
Hello,
It's possible to remove an xmlElement in the onePage by api?
I try out the following things.
1. GetContent with oneNoteApp.GetPageContent(...)
Result:
<?xml version="1.0"?>
<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2010/onenote" ID="{67AE1C64-ACA7-4DF6-9CBE-EE0F4C37C2CB}{1}{E19560793461111514907320169340014166064608271}" name="Seite ohne Titel" dateTime="2020-06-05T08:01:45.000Z" lastModifiedTime="2020-06-05T08:53:44.000Z" pageLevel="1" selected="partial" lang="de">
<one:QuickStyleDef index="0" name="PageTitle" fontColor="automatic" highlightColor="automatic" font="Calibri Light" fontSize="20.0" spaceBefore="0.0" spaceAfter="0.0" />
<one:QuickStyleDef index="1" name="p" fontColor="automatic" highlightColor="automatic" font="Calibri" fontSize="11.0" spaceBefore="0.0" spaceAfter="0.0" />
<one:PageSettings RTL="false" color="automatic">
<one:PageSize>
<one:Automatic />
</one:PageSize>
<one:RuleLines visible="false" />
</one:PageSettings>
<one:Title selected="partial" lang="de">
<one:OE author="" authorInitials="MT" lastModifiedBy="" lastModifiedByInitials="MT" creationTime="2020-06-05T08:14:24.000Z" lastModifiedTime="2020-06-05T08:14:24.000Z" objectID="{24B28869-2118-4D0C-A3AE-5CD72DE95CE5}{15}{B0}" alignment="left" quickStyleIndex="0" selected="partial">
<one:T selected="all"><![CDATA[]]></one:T>
</one:OE>
</one:Title>
<one:Outline author="" authorInitials="MT" lastModifiedBy="" lastModifiedByInitials="MT" lastModifiedTime="2020-06-05T08:15:55.000Z" objectID="{28C8BE49-4F84-414D-A20D-6EB99E8728AE}{63}{B0}">
<one:Position x="36.0" y="86.4000015258789" z="0" />
<one:Size width="72.0" height="13.42771339416504" />
<one:OEChildren>
<one:OE creationTime="2020-06-05T08:15:55.000Z" lastModifiedTime="2020-06-05T08:15:55.000Z" objectID="{28C8BE49-4F84-414D-A20D-6EB99E8728AE}{64}{B0}" alignment="left" quickStyleIndex="1">
<one:T><![CDATA[]]></one:T>
</one:OE>
</one:OEChildren>
</one:Outline>
</one:Page>
2. Now I remove outline element
<?xml version="1.0"?>
<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2010/onenote" ID="{67AE1C64-ACA7-4DF6-9CBE-EE0F4C37C2CB}{1}{E19560793461111514907320169340014166064608271}" name="Seite ohne Titel" dateTime="2020-06-05T08:01:45.000Z" lastModifiedTime="2020-06-05T08:53:44.000Z" pageLevel="1" selected="partial" lang="de">
<one:QuickStyleDef index="0" name="PageTitle" fontColor="automatic" highlightColor="automatic" font="Calibri Light" fontSize="20.0" spaceBefore="0.0" spaceAfter="0.0" />
<one:QuickStyleDef index="1" name="p" fontColor="automatic" highlightColor="automatic" font="Calibri" fontSize="11.0" spaceBefore="0.0" spaceAfter="0.0" />
<one:PageSettings RTL="false" color="automatic">
<one:PageSize>
<one:Automatic />
</one:PageSize>
<one:RuleLines visible="false" />
</one:PageSettings>
<one:Title selected="partial" lang="de">
<one:OE author="" authorInitials="MT" lastModifiedBy="l" lastModifiedByInitials="MT" creationTime="2020-06-05T08:14:24.000Z" lastModifiedTime="2020-06-05T08:14:24.000Z" objectID="{24B28869-2118-4D0C-A3AE-5CD72DE95CE5}{15}{B0}" alignment="left" quickStyleIndex="0" selected="partial">
<one:T selected="all"><![CDATA[]]></one:T>
</one:OE>
</one:Title>
</one:Page>
3. Update page content with method: oneNoteApp.UpdatePageContent(...)
4. Result is the like after step 1.
What I'm doing wrong to remove an element from the OneNote page?
Thanks for your help.
Best regards,
Mitch |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Hello Mitch,
This should work. You can send me your project and test notebook(s) to the support email address; find it in {Add-in Express installation folder}\readme.txt; please make sure your email contains a link to this topic.
Andrei Smolin
Add-in Express Team Leader |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Hello Mitch,
Alas, that was my fault. The description of the UpdatePageContent method at https://docs.microsoft.com/en-us/office/client-developer/onenote/application-interface-onenote#page-content-methods contains this paragraph:
The only objects that you must include in the XML code that you pass to the UpdatePageContent method are page-level objects (such as outlines, images on the page, or ink on the page) that have changed. This method does not modify or remove page-level objects that you do not specify in the bstrPageChangesXmlIn parameter. The method entirely replaces page-level objects, such as outlines, whose IDs match those of the objects you pass. Consequently, you must fully specify all page-level objects in your code, including their existing content and changes you want to make to them.
The method deleting an object is DeletePageContent; see the same page. It requires that you specify the page Id and the object id.
I'm sorry.
Andrei Smolin
Add-in Express Team Leader |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
The code below works for me.
After my first test, starting OneNote produced a OneNote message sort of "we are recovering". I suppose - and it would be natural to expect this - that OneNote requires releasing COM objects. Whence the ReleaseComObject calls in my code.
Andrei Smolin
Add-in Express Team Leader
OneNote.Windows windows = OneNoteApp.Windows;
OneNote.Window window = windows.CurrentWindow;
string pageId = window.CurrentPageId;
Marshal.ReleaseComObject(window); window = null;
Marshal.ReleaseComObject(windows); windows = null;
OneNoteApp.GetPageContent(pageId,out string pageContent);
XDocument doc = XDocument.Parse(pageContent);
XElement page = doc.Root;
XNamespace oneNoteNamespace = page.Name.Namespace;
XElement firstOutline = page.Descendants(oneNoteNamespace+ "Outline").FirstOrDefault();
string outlineId = firstOutline.Attribute("objectID").Value;
OneNoteApp.DeletePageContent(pageId, outlineId);
|
|