SP.ClientContext object
Represents the context for objects and operations.
Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013
var object = new SP.ClientContext()
Members
The ClientContext object has the following members.
Constructor
The ClientContext object has the following constructor.
Constructor |
Description |
---|---|
Initializes a new instance of the ClientContext object for the specified SharePoint site. |
Methods
The ClientContext object has the following methods.
Method |
Description |
---|---|
Casts the specified client object to a derived type. |
|
Disposes of the context. |
|
Executes the current pending request asynchronously on the server. |
|
Retrieves the properties of a client object from the server. |
|
Retrieves an enumerable sequence of child client objects from the specified collection. |
|
Raises the ExecutingWebRequest event. |
|
Parses the specified JavaScript Object Notation (JSON) string and gets an object from it. |
Properties
The ClientContext object has the following properties.
Property |
Description |
---|---|
Gets or sets the name of the runtime where the current client application is located. |
|
Gets the current client context of the client-side object model (CSOM) runtime. |
|
Gets or sets a value that indicates whether form digest handling is enabled. |
|
Gets a value that indicates whether the client context has a pending request. |
|
Gets the client request that is sent to the server when the next executeQueryAsync method is executed. |
|
Gets or sets the request timeout in milliseconds |
|
Gets the build version of Microsoft.SharePoint.Client.ServerRuntime.dll on the server. |
|
Gets the schema version of Microsoft.SharePoint.Client.ServerRuntime.dll on the server. |
|
Gets the version of the current instance of SharePoint 2013. |
|
Gets the site collection that is associated with the client context. |
|
Gets or sets the trace correlation ID used by the server. |
|
Gets the URL associated with the runtime context. |
|
Gets the website that is associated with the client context. |
Remarks
Use the ClientContext object to return context information about the current web application, site, site collection, or server version.
Example
The following code example creates an instance of the client context object, which is used to access the SharePoint object model. The example gets the current context by using the current property.
var clientContext;
var website;
// Make sure the SharePoint script file 'sp.js' is loaded before your
// code runs.
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
// Create an instance of the current context.
function sharePointReady() {
clientContext = SP.ClientContext.get_current();
website = clientContext.get_web();
clientContext.load(website);
clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
}
function onRequestSucceeded() {
alert(website.get_url());
}
function onRequestFailed(sender, args) {
alert('Error: ' + args.get_message());
}
See also
Other resources
Complete basic operations using JavaScript library code in SharePoint 2013