OneNote notebooks can be manually saved to the Sharepoint document library so users may share the notebook in the work. It is useful feature e.g. for workspaces which are often used in Sharepoint. But as it often happen those actions which can be done manually are not always so simple when we will need to automate the process, e.g. when we need to provision ready for use OneNote notebook during creation of the site. In this article I will show how it can be done.
First of all we need to make some preparation work: we need to prepare notebook template which will be provisioned to our doclib. In order to do this create new document library manually and select “Microsoft OneNote 2010 Notebook” in Document template list:
So under New document you should see OneNote icon:
Create new document here. It will open OneNote client where you will need to specify name of the new notebook when it will unpack the new notebook:
During unpacking it will create local copy of the notebook in your file system under “C:\Users\username\Documents\OneNote Notebooks” location. Now we should save this notebook to the Sharepoint document library: File > Share > Add a place > Office 365 SharePoint and put url of your site in the opened dialog. By default it only shows “Office 365 SharePoint”, but if you will put url manually, it should also allow to save it in on-premise site (see Getting OneNote 2013 to Work With On-Premise SharePoint):
After that if you will go to the document library you will see the saved notebook there:
Internally OneNote notebooks are similar to document sets which in turn close to the folders. Moreover if you will check add Content type column to the doclib view, it will show that notebook has Folder content type as it shown on the picture above. Now open document library in Explorer view: it will show the notebook as regular folder. Copy this folder to the local file system. It will contain 2 files:
- New Section 1.one
- Open Notebook.onetoc2
This folder with files will be used as template when during provisioning. However here we will face with the problem: if we will just copy this folder back to the document library but with different name, we will see that it will become regular Sharepoint folder:
On this picture we see that original notebook saved from OneNote client has correct icon, while the same file copied from local file system looks and behaves like regular folder. I.e. when user will click on such copied notebook, then instead of opening OneNote app (web app or desktop client) it will just go inside the folder where 2 mentioned files will be shown. This is definitely not what we want.
Let’s check the difference between these 2 folders e.g. in Sharepoint client browser (similar to the Sharepoint manager, but works also for O365):
As you can see real notebook has HTML File type set to “OneNote.Notebook”. The same difference also can be found for the ProgId field:
Another found difference is that real notebook has Title specified, while copied – not. Now the fix is quite obvious: we need to set ProgId for the copied Notebook (and Title for safety) in order to make it “real” notebook. Here is the code which makes the trick:
The same thing can be also done via client object model:
After fix copied notebook will look and behave like real OneNote notebook:
This code can be added to the feature receiver or to the web provisioned handler. Also you will need to provision 2 OneNote files via module to your document library before it will run:
Provided approach works both in farms and sandbox solution, so you may use it also in Sharepoint online.
Update 2015-09-22: second part of this article is available here.