Using Client Object Model In SharePoint
2012-02-29 15:50
519 查看
In SharePoint 2010 there are a number of object models that can be used by developers to access the server. The Client Object Model (Client OM) is a unified model which uses the same or similar programming concepts as the Server Object Model (Server OM).
We can use it like this:
Get all list item from a list:
View Code
Attention:
First the code gets a list object by using the GetByTitle method. Remember, this list object has no data in it; it does not have data in any of its properties until the application calls the ExecuteQuery method.
It then calls the "GetItems" method on the list object, even though that list object is not populated with data.
It finally calls the "Load" method on both the list object and listItems object, and then calls the "ExecuteQuery" method.
Reference:Using the SharePoint Foundation 2010 Managed Client Object Model
We can use it like this:
Get all list item from a list:
View Code
try{ ClientContext context = new ClientContext("YourSiteURL"); Site mySite = context.Site; Web myWeb = mySite.OpenWeb(""); List myList = myWeb.Lists.GetByTitle("YourListTitle"); CamlQuery query = new CamlQuery(); query.ViewXml = "<View/>"; ListItemCollection allitems = myList.GetItems(query); context.Load(myList); context.Load(allitems, items => items.Include(m => m["ID"], m => m["Title"])); context.ExecuteQuery(); foreach (ListItem item in allitems) { //do something } } catch(Exception ex) { //throw the exception }
Attention:
First the code gets a list object by using the GetByTitle method. Remember, this list object has no data in it; it does not have data in any of its properties until the application calls the ExecuteQuery method.
It then calls the "GetItems" method on the list object, even though that list object is not populated with data.
It finally calls the "Load" method on both the list object and listItems object, and then calls the "ExecuteQuery" method.
Reference:Using the SharePoint Foundation 2010 Managed Client Object Model
相关文章推荐
- Using the SharePoint 2010 Client Object Model_part_5
- Using the SharePoint 2010 Client Object Model_Part_6
- Using the SharePoint 2010 Client Object Model_Part_6
- Using the SharePoint 2010 Client Object Model_part_1
- Using the SharePoint 2010 Client Object Model_part_2
- Using the SharePoint 2010 Client Object Model_part_3
- Using the SharePoint 2010 Client Object Model_part_4
- Using the SharePoint 2010 Client Object Model_part_5
- Using the SharePoint 2010 Client Object Model_part_1
- Using the SharePoint 2010 Client Object Model_Part_6
- Using the SharePoint 2010 Client Object Model_part_1
- Using the SharePoint 2010 Client Object Model_part_2
- Using the SharePoint 2010 Client Object Model_part_2
- Using the SharePoint 2010 Client Object Model_part_3
- Using the SharePoint 2010 Client Object Model_part_3
- Get the metadata value using client object model from the sharepoint 2010
- Using the SharePoint 2010 Client Object Model_part_4
- Using the SharePoint 2010 Client Object Model_part_4
- Update metadata value using server object model in sharepoint 2013
- Using the SharePoint 2010 Client Object Model_part_5