zoukankan      html  css  js  c++  java
  • 用客户端模型访问SharePoint数据制作网站新闻列表

    在用客户端模型访问SharePoint数据首先要添加两个引用,一个是Microsoft.SharePoint.Client,另一个是Microsoft.SharePoint.Client.Runtime

    在程序要引用Microsoft.SharePoint.Client命名空间

    1.下面是一个简单的例子访问SharePoint列表的数据,读取的是列表名称为新闻列表,其中

    复制代码
     ClientContext ct = new ClientContext("http://moss:84");
    NetworkCredential nw = CredentialCache.DefaultNetworkCredentials;
    ct.Credentials = nw;
    Microsoft.SharePoint.Client.Web web = ct.Web;

    List lst = web.Lists.GetByTitle("新闻列表");
    CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml = "<View/>";
    Microsoft.SharePoint.Client.ListItemCollection lts = lst.GetItems(camlQuery);
    FieldCollection flds = lst.Fields;
    ct.Load(lst);
    ct.Load(lts);
    ct.Load(flds);
    ct.ExecuteQuery();

    // string fName = string.Empty;
    //foreach (Field f in flds)
    //{
    // if (f.Title == "置顶图片")
    // {
    // fName = f.InternalName;
    // break;
    // }
    //}
                    //下面是读取SPFieldUrlValue字段的值,其值包含两个值,一个是URL,一个是Description
    //foreach (Microsoft.SharePoint.Client.ListItem lt in lts)
    //{
    //if (lt[fName]!=null)
    //{
    // FieldUrlValue fURL = new FieldUrlValue();
    // fURL = (FieldUrlValue)lt[fName];
    // Response.Write("ID:"+i.ToString()+",LID:"+lt.Id+","+fURL.Url);
    // Response.Write("<br/>");
    // i++;
    //}
    //Response.Write(lt[fName]);
    //Response.Write("<br/>");
    // }
    Microsoft.SharePoint.Client.ListItem lt = lts[0];
    foreach (Microsoft.SharePoint.Client.Field f in flds)
    {
    Response.Write("Field Name: "+f.Title+":Field InterName: "+f.InternalName);
    Response.Write("<br/>");
    }
    复制代码
  • 相关阅读:
    题解 P3842 【[TJOI2007]线段】
    题解 CF1366A 【Shovels and Swords】
    题解 CF1391D
    题解 CF1374B 【Multiply by 2, divide by 6】
    CSP-J2020爆零记
    YbtOJ20025 放置石子
    YbtOJ20001 立方数差
    [仅供参考]W-RB的码风及要求
    [敲黑板]CSP考试策略
    [水沝淼㵘]向量水解
  • 原文地址:https://www.cnblogs.com/ningang/p/4321780.html
Copyright © 2011-2022 走看看