【问题标题】:<nativehr>0x80070057</nativehr><nativestack></nativestack> When creating a Choice field in a Sharepoint list<nativehr>0x80070057</nativehr><nativestack></nativestack> 在 Sharepoint 列表中创建选择字段时
【发布时间】:2016-04-26 20:41:31
【问题描述】:

我正在通过 Web 方法以编程方式创建一个 sharepoint 2010 站点。创建站点时 - 它会触发“功能激活”事件接收器。在这个事件接收器中,我正在网站上创建列表并向它们添加字段。

我正在创建的字段之一是选择字段(下拉列表)。我向该控件添加了几个选项,但发现在创建站点时,如果我下拉该字段,列表中没有选项。通过网络研究,我意识到我需要调用我选择的字段的更新方法。一旦我这样做了,网站的创建就抛出了一个异常,描述如下: 0x80070057 不是很有帮助。

如果我注释掉网站再次创建的选择字段的更新方法没问题,但下拉菜单中没有选项。

SPFieldChoice fldTransmittalStatus =   
(SPFieldChoice)newList.Fields.CreateNewField(Microsoft.SharePoint.SPFieldType.Choice.ToString(), Constants.FIELD_TRANSMITTAL_STATUS);
newList.Fields.Add(fldTransmittalStatus);                  
fldTransmittalStatus.EditFormat = SPChoiceFormatType.Dropdown;
fldTransmittalStatus.Choices.Add("Sent");
fldTransmittalStatus.Choices.Add("Downloaded");
fldTransmittalStatus.Choices.Add("Received");
fldTransmittalStatus.Choices.Add("Resent");
fldTransmittalStatus.Choices.Add("Cancelled");
fldTransmittalStatus.Update(); // when present, this line causes the site creation to fail
. . . . 
. . . . 
newList.Update();

我还将这个字段包含在默认视图中。

SPView defaultView = newList.DefaultView;
defaultView.ViewFields.Add(newList.Fields.GetField(Constants.FIELD_TRANSMITTAL_STATUS));

【问题讨论】:

    标签: c# .net sharepoint


    【解决方案1】:

    在调用字段的更新方法之前尝试更新列表

    【讨论】:

    • 谢谢。这真的很有帮助。
    • 事实证明,我不仅需要在更新列表后添加选择选项,而且我什至需要更新对列表的对象引用。 SPFieldChoice fldTransmittalStatus = (SPFieldChoice)newList.Fields[Constants.FIELD_TRANSMITTAL_STATUS];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-26
    • 2017-03-09
    • 1970-01-01
    相关资源
    最近更新 更多