我想查询使用CAML(第一次做这个)列表项,并根据修改的日期,所以我可以接触到最新的文件对项目进行排序。但是,当试图根据ID获取SPListItem时,我失败了。获取基于指标项目从SharePoint CAML查询到SPListItemCollection
代码:
SPQuery query = new SPQuery();
String camlquery = "<OrderBy><FieldRef Name='Modified' Ascending='False' /></OrderBy>";
query.ViewAttributes = "Scope = 'Recursive'";
query.ViewFields = "<FieldRef Name='Modified' /><FieldRef Name='Title' /><FieldRef Name='Name' />";
query.Query = camlquery;
query.IncludeMandatoryColumns = true;
SPListItemCollection col = list.GetItems(query);
//failing here... I think
SPListItem item = col.GetItemById(0);
有没有办法从SPListItemCollection内获得基于其索引的SPListItem?
我已经试过
SPListItem item = col[0];
还没有运气。
这里是我得到的错误:
值不在预期的范围内。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。
异常详细信息:System.ArgumentException:值没有在预期的范围内。
是否检查集合确实包含的项目? 如果得到像命令错误“值没有在预期范围内”'COL [0]'它通常意味着空数组。 – banana 2013-02-17 10:47:14