我使用以下代码从我公司的Sharepoint下载列表到我的程序。列表名称是“Resurser”。
var context = new ClientContext(@"MY_SHAREPOINT_SERVER_URL");
var passWord = new SecureString();
foreach (char c in "MY_PASSWORD".ToCharArray()) passWord.AppendChar(c);
SharePointOnlineCredentials _myCredentials = new SharePointOnlineCredentials("MY_USERNAME", passWord);
context.Credentials = _myCredentials;
List list = context.Web.Lists.GetByTitle("Resurser");
CamlQuery query = new CamlQuery();
query.ViewXml = "<View/>";
ListItemCollection items = list.GetItems(query);
context.Load(list);
context.Load(items);
context.ExecuteQuery();
foreach (ListItem item in items)
{
Console.WriteLine(item.FieldValues["Title"]);
}
Console.ReadKey();
我可以清楚地看到,我只从列表中收到77个项目,而列表中有更多项目。
我怎么能:
答案 0 :(得分:0)
如果我理解了您的问题,那么您没有获得列表中所有可用字段的值,对吧?在这种情况下,您可以考虑显式使用ClientRuntimeContext.Load<T> method
指定要检索的字段值。以下示例演示了如何检索所有列表字段的值:
var list = ctx.Web.Lists.GetByTitle("Contacts");
ctx.Load(list, l => l.Fields);
ctx.ExecuteQuery();
//get all available fields in list
var fieldNames = list.Fields
.Where(f => f.FieldTypeKind != FieldType.Computed && f.FieldTypeKind != FieldType.File && f.FieldTypeKind != FieldType.Recurrence && f.FieldTypeKind != FieldType.CrossProjectLink && f.FieldTypeKind != FieldType.AllDayEvent)
.Select(f => f.InternalName).ToList();
//construct expression to retrieve all field values
var includes = fieldNames.Select(name => (Expression<Func<ListItemCollection, object>>) (icol => icol.Include(i => i[name])));
var items = list.GetItems(CamlQuery.CreateAllItemsQuery());
ctx.Load(items, includes.ToArray());
ctx.ExecuteQuery();