您的位置:首页 > 移动开发 > Objective-C

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

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: