下面是从 2007 年到 2010 年迁移的一段遗留代码。它获取作者和编辑器字段的值。实际上,这些值是相同的用户。当我以 SPAdmin 权限登录时,两个字段都可以正常工作。但是,在测试帐户下,尝试获取 Editor 字段的值失败,并出现以下异常:“值不在预期范围内”,而 Author 字段仍然可以正常工作。让我们看看代码:
SPQuery sPQuery = new SPQuery();
sPQuery.Query = queryString;
sPQuery.ExpandRecurrence = true;
sPQuery.CalendarDate = startDateTime;
sPQuery.DatesInUtc = false;
SPListItemCollection items = list.GetItems(sPQuery);
SPListItem item = items[0];
object author = item["Author"]; //works always, under any account
object editor = item["Editor"]; // **doesn't work under non-system account**
好吧,这行代码也总是适用于编辑器:
object editor = item.ParentList.GetItemById(item.ID)["Editor"];
所以我想知道这有什么问题,我应该检查什么。谢谢。