C# SPListItem索引器报告”;值不在预期范围内;
我有以下代码:C# SPListItem索引器报告”;值不在预期范围内;,c#,asp.net,sharepoint,C#,Asp.net,Sharepoint,我有以下代码: try { string customerName = SPContext.Current.Web.CurrentUser != null ? SPContext.Current.Web.CurrentUser.Name.ToString() : "Customer"; SPSecurity.RunWithElevatedPrivileges(delegate() { try { usin
try
{
string customerName = SPContext.Current.Web.CurrentUser != null ?
SPContext.Current.Web.CurrentUser.Name.ToString() : "Customer";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
try
{
using (SPSite site = new SPSite(this.DesignJobListUrl))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList list = web.GetList(this.DesignJobListUrl);
SPListItem newListItem = list.Items.Add();
newListItem["Customer Name"] = customerName;
newListItem["Design Id"] = this.DesignStartResponse.DesignJobId;
newListItem["Email"] = email;
newListItem.Update();
}
}
}
catch (Exception ex)
{
innerEx = ex;
}
});
问题是行newListItem[“Customer Name”]=customerName代码>
抛出的值不在预期范围内。
异常,我不知道原因。另外两项作业做得很好
错误出现在.NET web应用程序的上下文中。此处:
试试这个:
newListItem.Properties["Customer Name"] = customerName;
请确保在designer中,列表字段的名称与此完全相同:
“客户名称”、“设计Id”、“电子邮件”。
任何额外/缺失的空格、字母大小写差异都可能导致代码无法工作。请仔细查看,看看在关键时刻customerName的价值。这是SharePoint的吗?我记得当我使用它时,一条模糊的错误消息让我发疯。@B.ClayShannon该值是一个有效的11个字符StringsListItem实现了一个自定义索引器,该索引器正在应用值检查并引发该异常。“Customer Name”是什么类型的列,如果它是一个人员选择器,你不能给它分配一个字符串值,如果内存可用,你会看到与你描述的错误相似的错误。这样做了,异常就不再发生了。谢谢