SharePoint client object model (I) ECMAScript_javascript skills

Source: Internet
Author: User
Today, we will start introducing the SharePointClient object model. In short, SharePoint provides data services on the server through the WCF technology, the content provided by these services is equivalent to a subset of the SharePointAPI. The so-called client object model is to call the WCF service behind it to provide data. in order to reduce the access volume of data, data packets use JSON, we can also see that the design of the object model also adds a lot of considerations for reducing the amount of data traffic. There is nothing new in technology. you need to be willing to implement similar functions in SharePoint2007. of course, it is convenient for us to use many of them.


Three types of. NET hosting, ECMA scripts, and SilverLightClient.

This article describes how to use. NET hosted code to access the SharePoint object model.

Notes for ECMAScript Client OM

  • ECMAScript can only be used in SharePoint sites. ECMAScript cannot be used in other Asp. NET sites to access SharePoint site resources or cross-SharePoint sites;
  • JQuery and ECMAScript do not conflict with each other;
  • For security updates, add
  • In the code that you will see later, you can specify the content to be loaded to reduce the volume of loaded data, such as client. context. load (this. web, 'title', 'id', 'created '). the attribute value names here use the same system as CAML and are case sensitive;
  • To ensure that your code is called after SP. JS is loaded, you can use ExecuteOrDelayUntilScriptLoaded (myjsFunction, "sp. js ").

Let's look at a simple matching relationship between SharePoint OM and client OM:

Server OM Client OM
SPContext ClientContext
SPSite Site
SPWeb Web
SPList List
SPListItem ListItem
SPField Field

Let's take a look at the final result. it is a preliminary plan function. it mainly designs the creation, query, and management of the list, and also involves the Case of uploading files, in the future, if there are any important items, they will be added gradually.

The link in will call the UI Javascript interface to create the SharePoint2010 pop-up window. the background page of the pop-up window is located in the SitePage Document Library. Please note that this is only applicable to the WebPart page, if it is not enabled, an error will be reported: "The Ribbon Tab with id:" Ribbon. read "has not been made available for this page or does not exist ".

(Note: this Page will not be used later. it is only used to explain Ribbon)

Creation list:

First, add the following two Script links through Designer:


ECMAScriptOM and. NET Managed ClientOM (will be discussed later) are similar, but there are also several points to note:

  1. Server URLs cannot be used in ClientContext;
  2. Does not support LINQ;
  3. Essentially, ECMAScript OM is asynchronous.

The code is very simple and easy to understand. there is a fun thing in it: SP. UI. Notify. addNotification. through this class, you can display the prompt message in the call screen, which is very SharePoint.

The demo result is as follows:

Enter the List name in the text box and click "Create List". after the List is generated, the system prompts "List test1 created" in the upper right corner. In this example, annoucement is used as the List type.

The source code is as follows:

The code is as follows:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.