您的位置:首页 > 运维架构 > 网站架构

用客户端模型访问SharePoint数据制作网站新闻列表

2015-03-08 15:34 447 查看

用客户端模型访问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/>");
}


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