Working With SharePoint Document Library Using Napa Office 365 Development Tools


In this article, we will learn how to create a folder in the Sharepoint document library using SharePoint-hosted SharePoint Add-in with Napa Office 365 development tools. Sharepoint's basic operations are used by JavaScript Object Model here. If there are any changes, post your comments here.

Develop the project using the method given below in NAPA tool

  • On your developer site, open Napa Office 365 development tools and then choose "Add New Project".
  • Choose the app for SharePoint template, name the project, create Site and then select the "Create" button.
  • Replace APP.js with the source code given below.
  • Publish your app.


  • The important steps are given below, which are to be followed before creating the app.
  • Specify the permissions that your app needs.

    • Choose the "Properties" button at the bottom of the page.
    • In the Properties window, choose "Permissions".
    • In the "Content" category, set the "Write" permissions for the Tenant scope.
    • In the Social category, set the "Read" permissions for the 'User Profiles" scope.
    • Close the "Properties" window.

Important things we need to know 

  • Represents the SharePoint Objects and Operations context.
  • This is used to access SiteCollection, SubSite, List,Library etc.
  • This is used to perform async calls to the SharePoint to accessing data.
  • Load method: Retrieves the properties of a client object from the server.
  • executeQueryAsync method: Executes the current pending request asynchronously on the server.

Reference the required libraries

Before using the JSOM, you must reference the following libraries, in exact order.

  1. ASP.NET Ajax library
  2. sp.runtime.js file
  3. sp.js file

Creating, updating, and deleting the lists through Client Object Model works similar to the Server Object Model using .NET Framework (CSOM,SSOM). The operations do not complete until and unless you call the executeQueryAsync(succeededCallback, failedCallback) function.

SharePoint 2013 introduces a NAPA tool service, which is comparable to the existing SharePoint Client Object Model. NAPA Tools can be used to perform Create, Read, Update and Delete (CRUD) operations from their apps for SharePoint.

The add-in that you’ll create includes the controls and the code to manage the lists and list items.

Choose the kind of add-in you want to create, name the project, and then press the "Create" button.

Common steps for all NAPA tool deployment

NAPA is a tool, which you can use to create SharePoint-hosted SharePoint add-ins. We can't create a PHA (Provider Hosted App), using NAPA Tools.

Click "Create" button.

Default .aspx display is like the pic, shown above and App.Js file looks, as shown.

You can add more .js files and add the code to it instead of it to the existing file.

Now, publish your app.

Choose the "Click here to launch your add-in in a new window" link.

Click "Trust it " option to deploy your app here. This action will be followed by a login popup window which will come and ask for your credentials.

Enter your credentials and then click "OK".

In the App.js, declare variables to store the Host Web and App. 

  1. var hostWebUrl;  
  2. var appWebUrl;  
Get the Host Web and App Web Url in document.ready,

  1. hostWebUrl= decodeURIComponent(manageQueryStringParameter('SPHostUrl'));  
  2. appWebUrl = decodeURIComponent(manageQueryStringParameter('SPAppWebUrl'));  
In the above code, SPHostUrl represents the full URL of the host site and SPAppWebUrl represents the full URL of the app web.
  1. <script type="text/javascript">  
  2.     var hostweburl;  
  4.     // Load the required SharePoint libraries.  
  5.     $(document).ready(function () {  
  7.         // Get the URI decoded URLs.  
  8.         hostweburl =decodeURIComponent( getQueryStringParameter("SPHostUrl") );  
  10.         // The js files are in a URL in the form:  
  11.         // web_url/_layouts/15/resource_file  
  12.         var scriptbase = hostweburl + "/_layouts/15/";  
  14.         // Load the js files and continue to  
  15.              $.getScript(scriptbase + "SP.Runtime.js",  
  16.             function () {  
  17.                 $.getScript(scriptbase + "SP.js", createFolder);  
  18.             }  
  19.         );  
  20.     });  
  22.  function createFolder() {  
  23.     var clientContext;  
  24.     var _Web;  
  25.     var _List;  
  26.     var _itemCreateInfo;  
  28.     clientContext = new SP.ClientContext.get_current();  
  29.     _Web= clientContext.get_web();  
  30.     _List= oWebsite.get_lists().getByTitle("Tutotrialdocuments");  
  32.     _itemCreateInfo= new SP.ListItemCreationInformation();  
  33.     _itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);  
  34.     _itemCreateInfo.set_leafName("Customfolder");  
  35.     this._ListItem = oList.addItem(itemCreateInfo);  
  36.     this._ListItem.set_item("Title""Customfolder!");  
  37.     this._ListItem.update();  
  39.     clientContext.load(this._ListItem);  
  40.     clientContext.executeQueryAsync(  
  41.         Function.createDelegate(this, success),  
  42.         Function.createDelegate(this, error)  
  43.     );  
  45.     function success() {  
  46.         alert(“New folder Created successfully”);  
  47.     }  
  49.     function error(sender,args) {  
  50.     alert( "Request failed: " + arguments[1].get_message();  
  51.     }  
  52. }  
  54.     // Function to retrieve a query string value.  
  55.     // For production purposes you may want to use  
  56.     // a library to handle the query string.  
  57.     function getQueryStringParameter(paramToRetrieve) {  
  58.         var params =  
  59.             document.URL.split("?")[1].split("&");  
  60.         var strParams = "";  
  61.         for (var i = 0; i < params.length; i = i + 1) {  
  62.             var singleParam = params[i].split("=");  
  63.             if (singleParam[0] == paramToRetrieve)  
  64.                 return singleParam[1];  
  65.         }  
  66.     }  
  67. <script>   

Once the code is executed, go back to SharePoint site and check if the list operations executed successfully or not.

That's it. Thanks for reading the article.

Up Next
    Ebook Download
    View all
    View all