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

 

转载于:https://www.cnblogs.com/gzh4455/archive/2012/01/30/2331598.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值