This article has been published originally in German on the 1stQuad company blog.

With server-side code, it is fairly easy to create OneNote notebooks in SharePoint. In this article, I want to explain briefly how to achieve this with the  JavaScript Object Model (JSOM).

In a current project, one of the requirements was to create OneNote notebooks automatically in Office 365. This had to happen either with out-of-the-box functionality or via API calls (REST or JSOM). After a few tries, it turned out that doing it via JSOM seems to be the best (and only?) option.

Generally speaking, a OneNote notebook in SharePoint is nothing else but a folder that is handled in a very specific way. With server-side code, you can “turn” a regular folder into a OneNote notebook by setting the ProgId property of the corresponding SPListItem to “OneNote.Notebook”. As you can’t access ProgId via JSOM, a different way to implement this functionality has to be found. Luckily, you can achieve the same thing by setting the property “HTML File Type” of a folder.

The following code snippet shows a short example

//common variables
var context=SP.ClientContext.get_current(); 
var web=context.get_web();
var lists=web.get_lists();
var list=lists.getByTitle("Documents");

//create a new folder
var itemCreationInfo=new SP.ListItemCreationInformation();
itemCreationInfo.set_leafName("Name of the new Notebook");

//modify the folder to convert it into a OneNote notebook
var onenoteNotebook=list.addItem(itemCreationInfo);
onenoteNotebook.set_item("HTML_x0020_File_x0020_Type" ,"OneNote.Notebook");

//send the request
 //created successfully, do stuff if needed 
 //something went wrong, do stuff if needed

21 thoughts on “Creating OneNote notebooks in SharePoint via JSOM”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.