I'd like to export text from my application to MS OneNote and support Office versions: 2007, 2010, 2013 and 2016. I'm using the Microsoft.Office.Interop.OneNote.dll Version:12.0.
0 as it's supplied with all Office versions.
The problem is when I try to create a new OneNote page on Office 2013 using "CreateNewPage" I'm getting the exception:
hrSectionReadOnly 0x8004200b
The section is read-only.
I can see an attribute readOnly="true"
I've tried to change it and it's not helping. Still getting the same exception.
If I reference Microsoft.Office.Interop.OneNote.dll Version:15.0.0
then everything works fine.
Any ideas why it's read only and how can I overcome the problem?
Here is code example:
string strPath;
string sectionId;
string xml;
// points directly on OneNote's Unfiled section
_app.GetSpecialLocation(SpecialLocation.slUnfiledNotesSection, out strPath);
_app.OpenHierarchy(strPath, "", out sectionId, CreateFileType.cftSection);
_app.CreateNewPage(sectionId, out _sectionId, NewPageStyle.npsDefault);
var strImportXml = @"<?xml version='1.0' ?>
<one:Page xmlns:one='" + _oneNoteNamespace + "' ID='" + _sectionId + @"'>
<one:Title>
<one:OE>
<one:T>
<![CDATA[
]]>
</one:T>
</one:OE>
</one:Title>
<one:Outline>
<one:Meta name='Rumba' content='" + new Random().Next() + @"' />
<one:OEChildren>
<one:HTMLBlock>
<one:Data>
<![CDATA[My sample page]]>
</one:Data>
</one:HTMLBlock>
</one:OEChildren>
</one:Outline>
</one:Page>";
_app.UpdatePageContent(strImportXml, DateTime.MinValue);
_app.NavigateTo(_sectionId, String.Empty, true);