【发布时间】:2016-06-04 12:24:51
【问题描述】:
我是 Sharepoint 的新手,目前我想编写一个函数,我可以在其中读取数据并将数据写入 Sharepoint 页面。这是我要连接读写数据的URL的结构:https://mycompany.sharepoint.com/sites/SubSite/SubSite1/SitePages/Home.aspx
然后,我使用以下命令打开与它的连接:
ClientContext clientContext = new ClientContext("https://mycompany.sharepoint.com/sites/SubSite/SubSite1/");
clientContext.Credentials = new SharePointOnlineCredentials("user@mycompany.com", password);
我使用SecureString作为密码
然后,我将网站页面加载到列表中并读取每个字段以进行检查:
List colList = clientContext.Web.Lists.GetByTitle("Site Pages");
FieldCollection colfield = colList.Fields;
IEnumerable<Microsoft.SharePoint.Client.List> resultCollection = clientContext.LoadQuery(
clientContext.Web.Lists.Include(
list => list.Title,
list => list.Id));
clientContext.Load(colList);
clientContext.Load(colfield);
clientContext.ExecuteQuery();
然后我遍历每个字段进行检查
for(int i = 1; i <= 4; i++){
ListItem lst = colList.GetItemById(i);
foreach (Field field in colfield){
clientContext.Load(field);
clientContext.ExecuteQuery();
var val = lst[field.Title];
}
}
发现colList中有一些字段,比如:DataSource等包含这个异常:
The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested
我的问题是如何正确连接到 Sharepoint 网站页面以在其中读取和写入数据?
【问题讨论】:
标签: c# asp.net sharepoint