You can use the SharePoint client object model to retrieve, update and manage data in SharePoint 2013. SharePoint makes the object model available in several forms.
- .NET Framework redistributable assemblies
- JavaScript library
- REST/OData endpoints
- Windows Phone assemblies
- Silverlight redistributable assemblies
This article shows how to perform basic operations using the JavaScript object model. You can add a reference to the object model using HTML <script> tags.
The following sections describe tasks that you can complete programmatically and they include JavaScript code examples that demonstrate the operations.
Procedure
Open your SP Site in SharePoint 2013 Designer. Then select an Assets icon in designer ribbon to add a JavaScript file.
After adding a JavaScript file the file is available in the SharePoint Site Assets folder as in the following:
Go to the SP site page and add a new page to the SharePoint site.
After adding a page select an Insert button in the Ribbon Menu.
Then add a Content Editor Web part into the page.
Edit the WebPart and add a JavaScript file link to the content link.
Save the web part and save the page in the site. Click the button!
List Created Successfully.
Source Code
- <div><button onclick=" DeleteFolder ()">Click here to DeleteFolder </button></div>
-
- <div id="displayDiv"></div>
- <script type="text/javascript">
-
- function deleteFolder() {
- var clientContext;
- var oWebsite;
- var folderUrl;
-
- clientContext = new SP.ClientContext.get_current();
- oWebsite = clientContext.get_web();
-
- clientContext.load(oWebsite);
- clientContext.executeQueryAsync(function () {
- folderUrl = oWebsite.get_serverRelativeUrl() + "/Lists/Shared Documents/Folder1";
- this.folderToDelete = oWebsite.getFolderByServerRelativeUrl(folderUrl);
- this.folderToDelete.deleteObject();
-
- clientContext.executeQueryAsync(
- Function.createDelegate(this, successHandler),
- Function.createDelegate(this, errorHandler)
- );
- }, errorHandler);
-
- function successHandler() {
- displayDiv.innerHTML = "Go to the " +
- "<a href='../Lists/Shared Documents'>document library</a> " +
- "to make sure the folder is no longer there.";
- }
-
- function errorHandler() {
- displayDiv.innerHTML = "Request failed: " + arguments[1].get_message();
- }
- }
-
- </script>
Thanks for reading my article.