Wednesday, July 23, 2014

OneNote Custom Actions to support Create/Move Pages and Sections and conversion to Folder in SharePoint

This simple article is about OneNote documents and SharePoint integrations and what can be done to created, support and manage OneNote Document in SharePoint enviroment, in this case Document Library types.
This solution create custom Ribbons action and Custom Menu Item to create OneNote Document and manipulate the content of the OneNote and move to other OneNote documents.

This solution has 2 Ribbon Actions "New OneNote Document" to generate new OneNote Documents and "Convert to OneNote/Folder" where is made the manipulation of OneNote document to move their content.

This article has the following topics
  • Description of the Solution (Business case)
  • Implementation of the Solution in SharePoint Enviroment (Developers or IT Administrators).

PS:yep everything (code, video and article) was made in 1 hour, then is a simple article....

Here some links talking about this and some code associated:

Here is the Custom Actions to manage OneNote Documents:

Here a little description of the Custom Actions and what are doing.

New OneNote Document

This Ribbon option give the option to create a New OneNote Document using the Out of the Box Ribbon Area associated with Document Library.

After the name of the document is selected the file is included in the Document Library.

Convert to OneNote/Folder

This option give the option to user to manipulate the content of OneNote Document, since OneNote is a folder with multiple other documents like ".one" documents, this option gives the option to users to grab the content of the OneNote Document and move to other OneNote Documents as shown in the Video bellow.

PS: For this example i rename the OneNote Document to "OneExample"

You can use the custom Menu item option called "Convert to OneNote/Folder", both will do the same task 
PS:the image bellow has different name because was used for other example purpose to show the option in the Menu item. 

After selecte the option the OneNote Document is converted to Folder and are able to see the support documents for the OneNote.

With the Folder option activated, users are able to access to content of OneNote and can move Sections/Pages (.one files) aggregated in the OneNote document to another folder or other OneNote document as shown in the video bellow in the article.
After make the change and move of content you can convert Convert to OneNote Document again using 

After you select the option the convertion of the documet is done and returns to the old format "" 

How was configured(Implementation)

To configured this funcionalities i used the Processlynx Custom Action & Ribbon Manager for the customizations of the Ribbon and Actions associated.
But you can also use Visual Studio declarative XML or REST Custom Actions from SharePoint.

With Processlynx Custom Action & Ribbon Manager

This SharePoint App Manage the CustomActions in the HostWeb in a very eficient and user friendly way.
For more info about the tool here a link

 Include CommandUI.Ribbon for Custom Ribbon Actions

Was created 2 Ribbon Actions called "New OneNote Document" and "Convert to OneNote/Folder".
This Custom Action will create new OneNote Document and Convert the OneNote Document to Folder.

Configure "New OneNote Document"

This option will open a prompt option where you can add the name of the OneNote documet, after this a folder is created and ProgId is changed to "OneNote.Notebook".

Location: Ribbon.Documents.New

Action Script Code:

javascript: function AddOneNoteDocument() { 
var Doc = prompt("Name of OneNote Document", "");
var context=SP.ClientContext.get_current(); 
var web=context.get_web();
var lists=web.get_lists();
var list=lists.getById('{ListId}');

var itemCreationInfo=new SP.ListItemCreationInformation();

var onenoteNotebook=list.addItem(itemCreationInfo);
onenoteNotebook.set_item("HTML_x0020_File_x0020_Type" ,"OneNote.Notebook");

context.executeQueryAsync(function(){alert('One Note Created!');SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);},function(sender,args){ alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);});


Here a simple Form of the configuration:

Configure "Convert to OneNote/Folder"

This option will became enable when one folder or OneNote document is selected. When the option is selected Folder became a OneNote document or OneNote document became a Folder.

Location: Ribbon.Documents.Manage

Enable Script Code:

javascript: var EnableDisable = function() {
 this.clientContext = SP.ClientContext.get_current();
 this.selectedItems = SP.ListOperation.Selection.getSelectedItems(this.clientContext);
 if (selectedItems.length==1)
if (selectedItems[0].fsObjType == 1)
{return true;}
{return false;}
 if (selectedItems.length!=1)
 {return false;}


Action Script Code:

javascript: function runCode(GetListid){  
var values = SP.ListOperation.Selection.getSelectedItems();   
var clientContext = new SP.ClientContext.get_current();  
var targetList = clientContext.get_web().get_lists().getById(GetListid);  
var targetListItem = targetList.getItemById(values[0].id);  
clientContext.load(targetListItem, 'HTML_x0020_File_x0020_Type');  
if (targetListItem.get_item('HTML_x0020_File_x0020_Type')=="OneNote.Notebook")
if (confirm("Do you want to convert OneNote document to Folder?") == true) {
else{if (confirm("Do you want to convert Folder to OneNote document?") == true) {
} };
},function(sender,args){ alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());});
function ConvertToFormat(GetListid,Format){
var clientContext = new SP.ClientContext.get_current();  
var values = SP.ListOperation.Selection.getSelectedItems(); 
var oList = clientContext.get_web().get_lists().getById(GetListid);
    var oListItem = oList.getItemById(values[0].id);
    oListItem.set_item('HTML_x0020_File_x0020_Type', Format);
clientContext.executeQueryAsync(function(){alert('Convertion finish!');SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
},function(sender,args){ alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());});


Here a simple Form of the configuration:

 Include EditControlBlock

This option will include a new Menu item Option where you are able to make the same action as  "Convert to OneNote/Folder".

Include in the URL Action the following Script:

javascript:var GetListID=' {ListId} ';function ConvertToFormat(n,t){var i=new SP.ClientContext.get_current,u=SP.ListOperation.Selection.getSelectedItems(),f=i.get_web().get_lists().getById(n.trim()),r=f.getItemById(u[0].id);r.set_item("HTML_x0020_File_x0020_Type",t);r.update();i.executeQueryAsync(function(){alert("Convertion finish!");SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK)},function(n,t){alert("Request failed. "+t.get_message()+"\n"+t.get_stackTrace())})}function runCode(n){var r=SP.ListOperation.Selection.getSelectedItems(),t=new SP.ClientContext.get_current,u=t.get_web().get_lists().getById(n.trim()),i=u.getItemById(r[0].id);t.load(i,"HTML_x0020_File_x0020_Type");t.executeQueryAsync(function(){i.get_item("HTML_x0020_File_x0020_Type")=="OneNote.Notebook"?confirm("Do you want to convert OneNote document to Folder?")==!0&&ConvertToFormat(GetListID,""):confirm("Do you want to convert Folder to OneNote document?")==!0&&ConvertToFormat(GetListID,"OneNote.Notebook")},function(n,t){alert("Request failed. "+t.get_message()+"\n"+t.get_stackTrace())})}runCode(GetListID.trim());

Here a simple Form of the configuration:

Configure with SharePoint REST/JSOM or Declarative XML

For the Custom Ribbon/Actions you can include the Custom Ribbon Action with the following XML Structure example:

<CommandUIExtension xmlns="">
<CommandUIDefinition Location="<Add Location>.Controls._children">
<Button Id="My Custom Button" LabelText="My Custom Button" Image32by32="/_layouts/15/1033/images/formatmap32x32.png?rev=33" Image32by32Left="-168" Image32by32Top="-68" ToolTipTitle="My Custom Button" Command="My Custom Button.Command" TemplateAlias="o1" />
<CommandUIHandler Command="My Custom Button.Command" CommandAction="<Add action Code here>" EnabledScript="<Add validation Code here>" />

For the REST call you can use the following link
For SharePoint JSOM call you can use the following link

Video of the Configuration

Link references:

Hope you enjoy the simple article, 
Kind regards, 
Andre Lage
Post a Comment