0
votes

I've been recently working with OneNote 2013 Interop to create an add-on. I came on the part that I create a new page and I need to copy text from another page to the newly created one. I've been looking and searching over google to find an answer but seems like I can't find one for my situation.

OneNote 2013 Interop (NOT API)

I've already checked the XML structure and this is what I have at the moment.

My question looks very much the same like this one: How to write to a OneNote 2013 page using C# and the OneNote Interop

I wanted to add a link but my acc isn't verified yet ... Search for that title in stackoverflow and you will see it.

But mine is like mentioned with a new page. What I have at the moment is that I create elements on the page which results in this output:

<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2013/onenote" ID="{1384AF22-F63D-4880-9690-5C6038503D52}{1}{E1949529374926015356741973773722707113107541}" name="Page 3" dateTime="2016-07-20T05:49:31.000Z" lastModifiedTime="2016-07-20T05:49:31.000Z" pageLevel="2">
      <one:QuickStyleDef index="0" name="PageTitle" fontColor="automatic" highlightColor="automatic" font="Calibri Light" fontSize="20.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 lang="nl-BE">
        <one:OE author="Vince Eeckhout" authorInitials="VE" authorResolutionID="&lt;resolutionId provider=&quot;Windows Live&quot; hash=&quot;EkqFbCZ8WfIDi9LBAf7kjA==&quot;&gt;&lt;localId cid=&quot;1c606a1f4bf7dc24&quot;/&gt;&lt;/resolutionId&gt;" lastModifiedBy="Vince Eeckhout" lastModifiedByInitials="VE" lastModifiedByResolutionID="&lt;resolutionId provider=&quot;Windows Live&quot; hash=&quot;EkqFbCZ8WfIDi9LBAf7kjA==&quot;&gt;&lt;localId cid=&quot;1c606a1f4bf7dc24&quot;/&gt;&lt;/resolutionId&gt;" creationTime="2016-07-20T05:49:31.000Z" lastModifiedTime="2016-07-20T05:49:31.000Z" objectID="{D7A808C9-11B4-4A6C-BA23-C45EFB6722A8}{15}{B0}" alignment="left" quickStyleIndex="0">
          <one:T>Page 3</one:T>
        </one:OE>
      </one:Title>
      <one:Outline objectID="{A4942397-ED76-488C-91B8-CC0A0A5BEA4B}{10}{B0}">
        <one:Position x="36.0" y="86.4000015258789" z="0">
          <one:Size width="143.5806274414062" height="13.42771339416504">
            <one:OEChildren>
              <one:OE>
                <one:T><![CDATA[I'm content of the page]]></one:T>
              </one:OE>
            </one:OEChildren>
          </one:Size>
        </one:Position>
      </one:Outline>
    </one:Page>

When I look at the structure of an existing page the xml is as follows:

    <one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2010/onenote" ID="{D98A2E47-1AFB-06BD-2CF0-DFD632DCF8F1}{1}{E1820259626561303932420117111407808163080081}" name="Page 3" dateTime="2016-07-05T09:53:14.000Z" lastModifiedTime="2016-07-11T11:28:20.000Z" pageLevel="2" selected="partial" lang="nl-BE">
      <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 lang="nl-BE">
        <one:OE author="Vince Eeckhout" authorInitials="VE" lastModifiedBy="Vince Eeckhout" lastModifiedByInitials="VE" creationTime="2016-07-05T09:53:20.000Z" lastModifiedTime="2016-07-05T09:53:20.000Z" objectID="{22153F4F-1C83-017C-056B-278E501AC009}{15}{B0}" alignment="left" quickStyleIndex="0">
      <one:T><![CDATA[Page 3]]></one:T>
    </one:OE>
  </one:Title>
  <one:Outline author="Vince Eeckhout" authorInitials="VE" lastModifiedBy="Vince Eeckhout" lastModifiedByInitials="VE" lastModifiedTime="2016-07-11T11:26:56.000Z" objectID="{A4942397-ED76-488C-91B8-CC0A0A5BEA4B}{10}{B0}">
    <one:Position x="36.0" y="86.4000015258789" z="0" />
    <one:Size width="143.5806274414062" height="13.42771339416504" />
    <one:OEChildren>
      <one:OE creationTime="2016-07-11T11:26:53.000Z" lastModifiedTime="2016-07-11T11:26:53.000Z" objectID="{A4942397-ED76-488C-91B8-CC0A0A5BEA4B}{11}{B0}" alignment="left" quickStyleIndex="1">
        <one:T><![CDATA[I'm content of the page]]></one:T>
      </one:OE>
    </one:OEChildren>
  </one:Outline>
</one:Page>

This seems to be right in my opinion but I get an error when I want to update the content of my page:

Text is not allowed in the context of element '{http://schemas.microsoft.com/office/onenote/2013/onenote}Position' according to DTD/Schema.

Can you help me please on this one ?

Thank you for responding to this in advance ! :)

1

1 Answers

0
votes

I see some errors on your try:

according to ms onenote 2010 scheme "one:Position" and "one:Size" must not contain shown content. you put content inside them. Best practise is to make them self-closing.

Also, even if not in your case, strings in the title element can cause problems. so you should avoid generating text directly into your "one:T"-Element rather than generating a "CDATA"-Element inside your "one:T"-Element.

If you change the Position and Size-Elements to be self-closing, it should work ;)