Skip to content

How to automate OneNote library creation

July 25, 2013

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);
newLib.Update();
 
                
 
//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";
folderitem.Update();
 
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

 

onenote:http://sp2010/sites/onenote/test/test

 

And it works!

Advertisements

From → OneNote, Sharepoint

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: