OneNote inserting elements with UpdatePageContent

I tried to find out if it is possible to add content to oneNote page via UpdatePageContent in the link Microsoft.Office.Interop.OneNote.

I want to create a page with a default template that I created in XML, but the msdn documentation told me that this function only allows structure:

msdn doc:

The only objects that you must include in the XML code that you pass to the UpdatePageContent method are page-level objects (such as paths, images on the page, or ink on the page) that have changed. This method does not modify or delete page-level objects that you do not specify in the bstrPageChangesXmlIn parameter. The method completely replaces page-level objects, such as paths, whose identifiers match the identifiers of the objects you pass. Therefore, you must fully specify all page-level objects in your code, including their existing content and the changes you want them to make.

My question is: can I add an element to the page with this library? if so, how?

thanks

0
c # xml visual-studio-2010 onenote xsd
source share
3 answers

You can use the OMSpy tool to examine the structure of the page content. The following are some examples to help you get started:

To set the page title if you have a page

private static void SePageTitle(string pageId, string pageTitle) { Microsoft.Office.Interop.OneNote.Application m_app = new Microsoft.Office.Interop.OneNote.Application(); string strPagTitle = "<one:Page xmlns:one=\"http://schemas.microsoft.com/office/onenote/2010/onenote\" ID=\"{0}\" >" + "<one:Title selected=\"partial\" lang=\"en-US\">" + "<one:OE style=\"font-family:Calibri;font-size:17.0pt\">" + "<one:T><![CDATA[{1}]]></one:T> " + "</one:OE>" + "</one:Title>" + "</one:Page>"; strPagTitle = string.Format(strPagTitle, pageId, pageTitle); m_app.UpdatePageContent(strPagTitle); } 

Add an item to the page if you have a page:

  private static void SetElementInPage(string pageId) { Microsoft.Office.Interop.OneNote.Application m_app = new Microsoft.Office.Interop.OneNote.Application(); string strPageContent = "<one:Page xmlns:one=\"http://schemas.microsoft.com/office/onenote/2010/onenote\" ID=\"{0}\" >" + "<one:Outline>" + "<one:Position x=\"36.0\" y=\"86.4000015258789\" z=\"0\" />" + "<one:Size width=\"117.001953125\" height=\"40.28314971923828\" />" + "<one:OEChildren>" + "<one:OE>" + "<one:T><![CDATA[This is a sample data added to test out OneNote API functionality. Following is a list item.]]></one:T>" + "</one:OE>" + "</one:OEChildren>" + "<one:OEChildren indent=\"2\">" + "<one:OE alignment=\"left\">" + "<one:List>" + "<one:Bullet bullet=\"2\" fontSize=\"11.0\" />" + "</one:List>" + "<one:T><![CDATA[A for Apple]]></one:T>" + "</one:OE>" + "<one:OE alignment=\"left\">" + "<one:List>" + "<one:Bullet bullet=\"2\" fontSize=\"11.0\" />" + "</one:List>" + "<one:T><![CDATA[B for Ball]]></one:T>" + "</one:OE>" + "<one:OE alignment=\"left\">" + "<one:List>" + "<one:Bullet bullet=\"2\" fontSize=\"11.0\" />" + "</one:List>" + "<one:T><![CDATA[C for Cat]]></one:T>" + "</one:OE>" + "</one:OEChildren>" + "</one:Outline>" + "</one:Page>"; strPageContent = string.Format(strPageContent, pageId); m_app.UpdatePageContent(strPageContent); } 
+1
source share

Pl post post part for the next, when you ask, it will be easy for other SOF members to get the problem right.

for syntax and to solve your problem use Onepagenote, follow the links below.

http://msdn.microsoft.com/en-us/magazine/ff796230.aspx

http://social.msdn.microsoft.com/Forums/pl-PL/officegeneral/thread/4596510a-6509-4e3a-be08-c11131fa4663

0
source share

Why do it so much? You can simply create your template in OneNote, rather than using interop to get the Hierarchy. So after that you can take a section group (which will be your template) so that you can get the contents of the pages (s) inside each section of the section group.

I struggled to copy elements from one laptop to another, but each element has an ObjectID. This indicates that this item is known to this particular page. Remove this attribute (so not only the attribute value), and OneNote will see the element as new and assign an ObjectID to the element.

Sample code how I removed the ID and objectID from the page:

 string xml; OneApplication.GetPageContent(page.Attributes["ID"].Value, out xml, PageInfo.piAll); var doc = XDocument.Parse(xml); var nodes = doc.Descendants(); foreach (var node in nodes) { if (node.Attribute("objectID") != null) { node.Attributes("objectID").Remove(); } else if (node.Attribute("ID") != null) { node.Attribute("ID").Value = ""; } } 

If you add all the elements to another page. You will see them. This works 100% because I did it myself :)

Hope this was helpful.

0
source share

All Articles