• Know more about me

Mai Omar Desouki

~ PFE @ Microsoft

Mai Omar Desouki

Daily Archives: August 12, 2013

SharePoint 2013 CSOM – Retrieve only selected properties of a website

12 Monday Aug 2013

Posted by Mai Omar Desouki in SharePoint 2013, Visual Studio 2012

≈ Leave a comment


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.

context.ExecuteQuery();

// 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.

Share this:

  • Facebook
  • LinkedIn
  • Twitter
  • Email
  • Print
  • Reddit

Like this:

Like Loading...

Blog Visitors

  • 79,406 Visitors

Categories

  • About me (1)
  • Microsoft Teams (3)
    • SharePoint Online (1)
  • Migration (2)
  • SharePoint 15 (5)
  • SharePoint 2010 (56)
    • Content Types (1)
    • Developer Dashboard (1)
    • Document Set (1)
    • Events I am Speaking In (2)
    • External Lists (1)
    • FAQ (2)
    • FBA (1)
    • Form Based Authentication (1)
    • Integration of CRM 2011 with SharePoint 2010 (1)
    • JQuery (1)
    • Master Page (1)
    • My Site (1)
    • PowerShell (3)
    • SharePoint Administration (5)
    • SharePoint Branding (1)
    • SharePoint Customization (5)
    • SharePoint Designer (4)
    • SharePoint Designer Workflow (1)
    • SharePoint Events (2)
    • SharePoint Online (1)
    • SharePoint Permissions (1)
    • SharePoint Workflow (1)
    • User Profile (2)
    • User Profile Sync (1)
    • Videos (1)
    • WebParts (1)
    • Workflow (1)
  • SharePoint 2013 (87)
    • Cloud App (1)
    • Event Handler (1)
    • iPad (1)
    • IPhone (1)
    • Napa (1)
  • SharePoint Updates (1)
  • Visual Studio 2012 (3)

Tag Cloud

About me Document Set Events I am Speaking In FAQ FBA Form Based Authentication JQuery Master Page Microsoft Teams Migration My Site PowerShell SharePoint 15 SharePoint 2010 SharePoint 2013 SharePoint Administration SharePoint Branding SharePoint Customization SharePoint Designer SharePoint Designer Workflow SharePoint Events SharePoint Online SharePoint Permissions SharePoint Workflow User Profile User Profile Sync Videos Visual Studio 2012 WebParts Workflow

Calendar

August 2013
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Jul   Sep »

Archive

  • September 2020 (2)
  • May 2020 (2)
  • April 2020 (6)
  • March 2020 (1)
  • September 2019 (2)
  • July 2015 (1)
  • May 2015 (3)
  • April 2015 (1)
  • March 2015 (1)
  • February 2015 (2)
  • January 2015 (1)
  • October 2014 (1)
  • September 2014 (3)
  • June 2014 (7)
  • May 2014 (5)
  • April 2014 (4)
  • March 2014 (3)
  • February 2014 (1)
  • January 2014 (2)
  • December 2013 (6)
  • November 2013 (5)
  • October 2013 (6)
  • September 2013 (5)
  • August 2013 (5)
  • July 2013 (5)
  • June 2013 (2)
  • May 2013 (2)
  • February 2013 (2)
  • January 2013 (1)
  • October 2012 (2)
  • September 2012 (7)
  • August 2012 (15)
  • July 2012 (5)
  • June 2012 (2)
  • May 2012 (4)
  • April 2012 (2)
  • March 2012 (1)
  • August 2011 (3)
  • July 2011 (15)

Blog at WordPress.com.

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
%d bloggers like this: