我有一个SPListItem和一个列名数组。当我尝试使用以下代码访问SPListItem值时:
for(int i=0;i<arrColName.length;i++)
{
string tempValue = item[arrColName[i]].ToString();
// Works fine in case the the specific column in the list item is not null
// Argument exception - Values does not fall witing expected range
// exception in case the value //is null
}发布于 2012-06-08 16:47:29
我认为您使用了一个SPQuery来获取列表项,并且忘记了将该字段添加到SPQuery的viewfield属性中。
query.ViewFields = string.Format("<FieldRef Name=\"{0}\" Nullable=\"True\" />", mFieldName);通常,当你用场帐户测试你的程序时,代码会工作,对于普通用户,你会得到一个ArgumentException。
另一个导致ArgumentException的问题/特性是新的ListView阈值。如果您尝试访问的列表包含的项目太多,则会引发此异常。处理此问题的一种方法是使用powershell增加列表的阈值。
发布于 2009-10-21 14:04:23
不仅检查项目!= null,还检查项目“FieldName”!= null。因为如果你试图在null上调用.ToString(),你会得到异常。
如果内部名为"FieldName“的字段不存在,您也会得到一个异常。所以你可能会试着
SPFieldCollection fields = list.Fields;
foreach (SPListItem item in list.Items) {
if (fields.Contains("FieldName") && item["FieldName"] != null) {
string fieldValue = item["FieldName"].ToString();
}
}发布于 2010-09-07 12:47:43
我在自定义级联字段(或列)中也遇到过类似的情况。我按照下面的方法做了,它似乎对自定义字段类型起作用。
item.Properties["Country"] = "Mexico"; // custom field
item.Properties["nCity"] = "Cancun"; // custom field
item["Document Descriptions"] = "Test document description.";注意:我为定制列添加了item.Properties。不需要为内置字段类型添加属性(否则它们不起作用)。
https://stackoverflow.com/questions/1596062
复制相似问题