sharepoint

Topics related to sharepoint:

Getting started with sharepoint

Working with JavaScript Client Object Model (JSOM)

Background

The JavaScript Object Model was introduced in SharePoint 2010. It exposes on the client side many of the objects that were previously only accessible through server-side code or through dedicated web services.

Embedding JavaScript in SharePoint Pages

In SharePoint 2013 you can put your JavaScript in a Script Editor web part.

In SharePoint 2010 you can use the "content link" property of a Content Editor web part to link to an HTML file that contains your embedded script.

Object Reference

The constructors, methods, and properties of all objects found in the SP namespace are documented in the SharePoint 2013 client object model reference here.

The SharePoint 2010 JavaScript client object model reference is available here.

JSOM's Asynchronous Programming Pattern

When using the JavaScript client object model, code generally takes the following pattern:

  1. Obtain a ClientContext object.
  2. Use the ClientContext object to retrieve objects representing entities in the SharePoint object model, such as lists, folder, views.
  3. Queue up instructions to be performed against the objects. These instructions are not transmitted to the server yet.
  4. Use the load function to tell the ClientContext what information you want to receive back from the server.
  5. Invoke the ClientContext object's executeQueryAsync function to send the queued instructions to the server, passing two callback functions to run on success or failure.
  6. In the callback function, work with the results returned from the server.

Alternatives

Client-side alternatives to the JSOM include SharePoint's web services, REST endpoints, and the .NET client object model.

Working with Managed Client Side Object Model (CSOM)

  • Most examples are from MSDN.
  • To create a .NET managed client application that uses the client object model, you must set references to two client library DLLs: Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll. You can find it in %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\16\ISAPI folder or your SharePoint server.
  • or Install the Microsoft.SharePointOnline.CSOM NuGet Package, which will work "on prem" as well as in SP O365.
  • Most properties are value properties and before accessing them you need to explicitly call clientContext.Load() and clientContext.ExecuteQuery(). More info here: Call Load and ExecuteQuery Before Accessing Value Properties

Major Releases

REST Services

REST Service Endpoint URLs

The REST client access API was first introduced in SharePoint 2010, but was greatly expanded in SharePoint 2013. The REST API in SharePoint 2010 is accessed through the ListData web service at the /_vti_bin/ListData.svc url. SharePoint 2013 introduced the /_api/lists/ and /_api/web endpoint URLs, which behave slightly differently.

The above endpoint URLs should be preceded by http://server/site where server represents the name of the server, and site represents the name of, or path to, the specific site.

Example URL for...SharePoint 2010SharePoint 2013
Fetching a List:/_vti_bin/ListData.svc/ListName/_api/lists('ListGuid')
Fetching an Item:/_vti_bin/ListData.svc/ListName(1)/_api/lists('ListGuid')/items(1)
Fetching a Web:(no equivalent)/_api/web

Despite the differences in accessing lists and list items, working with those results is very similar in both versions.

Note that the ListData.svc service is still available in SharePoint 2013 for backwards compatibility.

Sending REST Requests

A REST request can be submitted via a native JavaScript XMLHttpRequest or via the jQuery AJAX wrapper construct.

XMLHttpRequest Syntax

var xhr = new XMLHttpRequest();
xhr.open(verb, url, true);
xhr.setRequestHeader("Content-Type","application/json");
xhr.send(data);

jQuery AJAX Syntax

$.ajax({
    method: verb,
    url: url,
    headers: { "Content-Type":"application/json" },
    data: data
});

For more details on sending requests via AJAX, see the JavaScript AJAX documentation.

Creating a provider hosted App

Working with Modal Dialog Boxes with JavaScript

The SP.UI.ModalDialog namespace was introduced to the JavaScript Object Model with SharePoint 2010, and is available in subsequent SharePoint versions 2013, Office365, and 2016.

Additional reference materials:

Working with Managed Server Side Object Model (full-trust)

Conceptual Hierarchy

In the SharePoint conceptual hierarchy, site collections contain sites, which in turn contain lists. A site collection (SPSite) has no explicit UI but always contains one root level site (accessible through the RootWeb property) and possibly additional subsites under that root site. A site or web (SPWeb) has a UI and contains lists/document libraries (SPList), pages with webparts, and items/documents (SPListItem).

Server-Side Caveats

  • To create an application that uses the SharePoint server-side object model, in your Visual Studio project you must add a reference to the Microsoft.SharePoint assembly which is listed under Framework Assemblies.
  • Applications using the Server Side Object Model (full-trust) can run only on a Windows Server that is hosting SharePoint.
  • You cannot connect to a SharePoint server other than the one the application is running on.

SharePoint 2013 Client Side Rendering

SharePoint App