zoukankan      html  css  js  c++  java
  • Using Client Object Model In SharePoint

    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
     1 try{
    2 ClientContext context = new ClientContext("YourSiteURL");
    3 Site mySite = context.Site;
    4 Web myWeb = mySite.OpenWeb("");
    5 List myList = myWeb.Lists.GetByTitle("YourListTitle");
    6 CamlQuery query = new CamlQuery();
    7 query.ViewXml = "<View/>";
    8 ListItemCollection allitems = myList.GetItems(query);
    9 context.Load(myList);
    10 context.Load(allitems, items => items.Include(m => m["ID"], m => m["Title"]));
    11 context.ExecuteQuery();
    12 foreach (ListItem item in allitems)
    13 {
    14 //do something
    15 }
    16 }
    17 catch(Exception ex)
    18 {
    19 //throw the exception
    20 }

    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

  • 相关阅读:
    php 建立类POST/GET 的HTTP请求
    上传文件
    golang精选100题带答案
    go面试
    golang反射
    go语言中type的几种使用
    写个版本迭代的方法 例如1.0.9 迭代为1.1.0 到10自动往前进1
    压缩文件和解压文件
    go语言中的文件创建,写入,读取,删除
    go面试题
  • 原文地址:https://www.cnblogs.com/leolis/p/2373560.html
Copyright © 2011-2022 走看看