In the previous part I showed how to provision ready for use OneNote notebook to Sharepoint site. Described method works but has one drawback: if you have many sites and need to create notebook in all of them, users who will work with several sites will always see the same notebook name and won’t know from which sites they are because all of them will have the same name “New Section 1” (remember that we provisioned 2 files in Notebook docset: “Open Notebook.onetoc2” and “New Section 1.one”). In this post we will show this issue.
User experience will be better if we will use different names for notebooks. E.g. we may use parent sites’ titles for notebooks. In this case users will be able to open notebooks from different sites in OneNote desktop application and will know from which site each notebook is:
It is quite simple to do. We need to rename “New Section 1.one” to {web title}.one in web provisioned handler or in feature receiver (depending how you implemented it) right after setting ProgId for the Notebook folder (changing of ProgId was described in previous part):
1: var list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, "OneNote"));
2: var folder = list.Folders.Cast<SPListItem>().FirstOrDefault(f =>
3: f.Url.EndsWith("Notebook"));
4: folder[SPBuiltInFieldId.Title] = "Notebook";
5: folder.ProgId = "OneNote.Notebook";
6: folder.Update();
7:
8: foreach (SPFile file in folder.Folder.Files)
9: {
10: if (string.Compare(file.Name, "New Section 1.one", true) == 0)
11: {
12: file.MoveTo(string.Format("OneNote/{Notebook/{0}.one", web.Title));
13: }
14: }
After that notebook will have the same title as parent web and users will be able to distinguish notebooks in OneNote as shown on the picture above.
No comments:
Post a Comment