list SharePoint 列表错误:“值不在预期范围内”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/603389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SharePoint List Error: "Value does not fall within the expected range"
提问by Oliver S
Hi I am developing using the SharePoint namespace and I ran into the following error when I try to retrieve a URL column from one of my lsits.
您好,我正在使用 SharePoint 命名空间进行开发,当我尝试从我的一个 lsits 中检索 URL 列时遇到以下错误。
"Value does not fall within the expected range"
All I am doing is:
我所做的就是:
item["URL"]
Can someone tell me what I can do about this?
有人能告诉我我能做些什么吗?
回答by Jason
The error definitely means that the field can't be found.
该错误肯定意味着找不到该字段。
Debug the process and look at the ListItem.Fields.SchemaXML
property to find its internal name, it may be saved internally as something other than URL
. You can also use the following method to get a list item value.
调试进程并查看ListItem.Fields.SchemaXML
属性以找到其内部名称,它可能在内部保存为URL
. 您还可以使用以下方法获取列表项值。
SPField l_field = l_item.Fields.GetField("URL");
string l_fieldValue = l_item[l_field.Id].ToString();
The GetField
method looks for a field by both DisplayName & InternalName.
该GetField
方法通过 DisplayName 和 InternalName 查找字段。
回答by Andy Mikula
To get the URL of an SPListItem
, use Item.Url
.
要获取 的 URL SPListItem
,请使用Item.Url
.
回答by Andy Mikula
public static string GetItemURLValue(SPListItem item, string fieldName)
{
string exit = "";
SPFieldUrlValue link = new SPFieldUrlValue(item[fieldName].ToString());
exit = link.Url;
return exit;
}
回答by strongopinions
There is a special method for retrieving URLs. Try this:
有一种特殊的方法来检索 URL。尝试这个:
SPListItem li = ...
SPFieldUrlValue fuv = new SPFieldUrlValue(li[strFieldName].ToString());
return fuv.Url;
回答by Vallabh Naik
Mine is a Windows application. I used to get this exception after I created the set up and tried deploying.
我的是一个 Windows 应用程序。我曾经在创建设置并尝试部署后遇到此异常。
My application needed to write in Excel and then save it. I used reference of COM component 'Microsoft Excel 11.0 Object'. I noticed when I add this reference actually 3 dll's appear in my reference list.
我的应用程序需要用 Excel 编写然后保存。我使用了 COM 组件“Microsoft Excel 11.0 Object”的参考。我注意到当我添加这个引用时,我的引用列表中实际上出现了 3 个 dll。
- Microsoft.office.core
- Excel
- VBIDE
- 微软.office.core
- 电子表格
- 视界
I removed the 'VBIDE' reference and my problem is solved.
我删除了“VBIDE”引用,我的问题就解决了。
回答by vapcguy
If it's just a column name and in "Single line of Text" format, what about:
如果它只是一个列名和“单行文本”格式,那么:
item["URL"] != null ? item["URL"].ToString() : "Not Found";
回答by Tundey
This usually means "URL" is not a field in the list.
这通常意味着“URL”不是列表中的字段。
If it's a promoted InfoPath column, try deactivating and re-activating the form template to the site. I have noticed that I have to do this whenever I add a new promoted field to an infopath template.
如果它是提升的 InfoPath 列,请尝试停用并重新激活网站的表单模板。我注意到,每当我向 infopath 模板添加新的提升字段时,我都必须这样做。