

If you want to work with OneNote content, you'll need a basic understanding of XML. This is just what I've gleaned from reading examples on the web (of course, you've already read all of those) and peeking into the way OneNote stores its data in XML using ONOMspy ( ). OnenoteApp.UpdatePageContent(doc.ToString()) Var content = outLine.Descendants(ns + "T").First() Var outLine = doc.Descendants(ns + "Outline").First() OnenoteApp.GetPageContent(pageId, out xml, ) Static string GetPageContent(string pageId) Var node = doc.Descendants(ns + nodeName).Where(n => n.Attribute("name").Value = objectName).FirstOrDefault() OnenoteApp.GetHierarchy(parentId, scope, out xml) Ĭase (): nodeName = "Notebook" break Ĭase (): nodeName = "Page" break Ĭase (): nodeName = "Section" break Static string GetObjectId(string parentId, OneNote.HierarchyScope scope, string objectName) OnenoteApp.GetHierarchy(null,, out xml) String firstPageId = GetObjectId(sectionId,, "MyPage") String sectionId = GetObjectId(notebookId,, "Sample_Section") String notebookId = GetObjectId(null,, "MyNotebook")

static Application onenoteApp = new Application() I hope that this can help people in the future.
#How to print to onenote 2013 how to#
Below is a nice, clean example of how to write to OneNote using C# and the OneNote interop. I asked the same question on MSDN forums and was given this great answer. The reason being that the value of "node" is null, any help would be greatly appreciated.
#How to print to onenote 2013 code#
However, there are 2 things about this solution that do not answer my question:ġ) The marked solution shows how to create a new page, not how to write text to it or how to populate the page with any information.Ģ) When I try to run the code that is marked as the solution, I get an error at the following line: var node = doc.Descendants(ns + nodeName).Where(n => n.Attribute("name").Value = objectName).FirstOrDefault() I have tried using this Stack Overflow answer: Most importantly I would really appreciate a code example that demonstrates how to write text to a OneNote 2013 Notebook Page. I vaguely understand how the OneNote Interop works through XML but any extra help understanding that would also be appreciated.

I have already viewed the MSDN articles on the OneNote Interop as well. I have taken a lot of time to research this and view the different examples online but none are able to help. There is no simple way to do this that I can see. I used the Microsoft code sample that shows how to change the name of a Section but I cannot find any code to write text to a Page.

Also many of the code examples are outdated and break when attempting to run them. I have looked at all of the code examples on the web and none answer this simple question or are able to do this. I need to be able to use C# code to write text to this Page, but I cannot figure out how or find any resources to do so. Currently I have a OneNote Notebook, with a Section titled "Sample_Section" and a Page called "MyPage". Using C# and the OneNote Interop, I would like to simply write text to an existing OneNote 2013 Page. I have seen many articles about this but all of them are either incomplete or do not answer my question.
