Use SharePoint csom to write efficient programs

Source: Internet
Author: User

The previous article briefly introduced the use of csom for programming. Today, I will talk about some tips in csom to make your program run faster.

Load some attributes separately

In the preceding example, we use the following code to return web object information:

VaR web = clientcontext. Web; clientcontext. Load (Web); // set Query Information

When querying Web information, the Web will return many attributes, many of which are not required. If we only need to return some attributes, we can use the following method:

var currentWeb = clientContext.Web;clientContext.Load(currentWeb, web => web.Title, web => web.Url, web => web.WebTemplate);clientContext.ExecuteQuery();

The returned message is in the following format:

We can see that only the required attributes are returned in the message format.

In the above two cases, the returned respone lengths are 1200 and 500, respectively. Therefore, if the network throughput is limited, the query attributes should be returned as little as possible, it plays an important role in improving efficiency.

Query set attributes

How does csom process the query of set information? For example, to obtain all list information on the Web, we can:

clientContext.Load(currentWeb.Lists);clientContext.ExecuteQuery();

At this time, all information about each list will be returned. If we only want to go back to the title and basetemplate of a list, we only need:

var currentWeb = clientContext.Web;clientContext.Load(currentWeb.Lists, lists => lists.Include(list => list.Title, list => list.BaseTemplate));

Or you can use:

clientContext.LoadQuery(currentWeb.Lists.Include(list => list.Title, list => list.BaseTemplate));clientContext.ExecuteQuery();

In both cases, in a web with 25 lists, the response packet lengths are 38963 and 8172, respectively. Therefore, when loading a set, selecting appropriate query conditions is crucial to performance.

 

Use SharePoint csom to write efficient programs

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.