Introduction

In this article, we will learn how to remove a folder in Sharepoint document library, using SharePoint-hosted SharePoint add-ins, using 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

Prerequisite

Basic and important things that we want to know are given below.

Sp.ClientContext

Reference the required libraries

Before using JSOM, you must reference the libraries in the order given below.

  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 similarly to 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 tool can be used to perform Create, Read, Update and Delete (CRUD) operations from their apps for SharePoint.

By following this article, you can learn how to create a simple SharePoint-hosted SharePoint add-in by using Napa. 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 choose 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 tool.

Click Create button.


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

You can add more .js file 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, followed by your login popup Window, which will come and ask your credentials.

Enter your credentials and then click OK.




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

  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 code given above, 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;
  3. // Load the required SharePoint libraries.
  4. $(document).ready(function () {
  5. // Get the URI decoded URLs.
  6. hostweburl =decodeURIComponent( getQueryStringParameter("SPHostUrl") );
  7. // The js files are in a URL in the form:
  8. // web_url/_layouts/15/resource_file
  9. var scriptbase = hostweburl + "/_layouts/15/";
  10. // Load the js files and continue to
  11. $.getScript(scriptbase + "SP.Runtime.js",
  12. function () {
  13. $.getScript(scriptbase + "SP.js", createFolder);
  14. }
  15. );
  16. });
  17. function deleteFolder(resultpanel) {
  18. var clientContext;
  19. var oweb;
  20. var _folderUrl;
  21. clientContext = new SP.ClientContext.get_current();
  22. oweb= clientContext.get_web();
  23. clientContext.load(oweb);
  24. clientContext.executeQueryAsync(function () {
  25. _folderUrl = oweb.get_serverRelativeUrl() + "/Lists/TutorialLibrarury/Folder1";
  26. this.folder = oWebsite.getFolderByServerRelativeUrl(_folderUrl);
  27. this.folder.deleteObject();
  28. clientContext.executeQueryAsync(
  29. Function.createDelegate(this, successHandler),
  30. Function.createDelegate(this, errorHandler)
  31. );
  32. }, errorHandler);
  33. function success() {
  34. alert(“New folder Deleted successfully”);
  35. }
  36. function error(sender,args) {
  37. alert( "Request failed: " + arguments[1].get_message();
  38. }
  39. }
  40. // Function to retrieve a query string value.
  41. // For production purposes you may want to use
  42. // a library to handle the query string.
  43. function getQueryStringParameter(paramToRetrieve) {
  44. var params =
  45. document.URL.split("?")[1].split("&");
  46. var strParams = "";
  47. for (var i = 0; i < params.length; i = i + 1) {
  48. var singleParam = params[i].split("=");
  49. if (singleParam[0] == paramToRetrieve)
  50. return singleParam[1];
  51. }
  52. }
  53. <script>

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

Thanks for reading the article.