Sometimes, the client is interested only in a few properties of an object. The SharePoint .NET Framework CSOM does not require you to get all properties from the object on a server—you can use anonymous methods, which can be lambda expressions, to specifically request property names. The client library will query only for those properties on the server, and the server will send only those properties to the client. This technique reduces unnecessary data transfer between the client and the server. It is also useful when the user does not have permission to one or more of the other, unused properties on an object. Note that you will need to add a using statement for System.Linq.

// Starting with ClientContext, the constructor requires a URL to the // server running SharePoint.

ClientContext context = new ClientContext(http://SiteUrl”);

// The SharePoint web at the URL.

Web web = context.Web;

// We want to retrieve the web’s title and description.

context.Load(web, w => w.Title, w => w.Description);

// Execute the query to server.


// Now, only the web’s title and description are available. If you

// try to print out other properties, the code will throw

// an exception because other properties are not available.

label1.Text = web.Title;

label1.Text = web. Description;


Note: If you try to access other properties, the code throws an exception because other properties are not available.