I’ve recently been asked to do the following automation.
We have a portal on our SharePoint site that has data about something – let us say projects.
And once we want to create a new project, we want to have
A new document library with some things set up (like versioning).
A OneNote notebook that the users can work on and sync their data
At first it looks pretty obvious, isn’t it?
Now the question comes – what is a OneNote book from the SharePoint prospective?
After some investigation I found out that OneNote notebook is just a folder, but there is a trick.
One cannot simply create a OneNote as a folder, what you need to provide is a thing called ProgID.
I made a simple sandboxed webpart that does ask for library name, and then just creates the library.
In the library a folder with the same name is created and set up to be OneNote notebook.
The code is this
var newLibId = web.Lists.Add(name, description, SPListTemplateType.DocumentLibrary);
var newLib = (SPDocumentLibrary)web.Lists.GetList(newLibId, true);
//Remember Document library is also a list in SharePoint
SPFolderCollection folders = web.GetFolder(newLib.RootFolder.ServerRelativeUrl).SubFolders;
//Create new folder
var newfolder = folders.Add(name);
var folderitem = newfolder.Item;
folderitem.ProgId = "OneNote.Notebook";
And at first it looks ok
But when you get inside it
You notice that the link "Open in OneNote" is missing.
To overcome this we’ve generated a link ourselves