<nativehr>0x80070057</nativehr><nativestack></nativestack> When creating a Choice field in a Sharepoint list
Try to update the list before you call the update method of the field
tassieboy
Adam is a software developer from Tasmania, Australia, working for a consulting engineering company. He is married and has two children. He is also a science fiction author, podcaster and youTuber. AdamDavidCollings.com
Updated on June 26, 2022Comments
-
tassieboy almost 2 years
I am programatically creating a sharepoint 2010 site in a web method. When the site is created - it fires off a 'feature activated' event receiver. In this event receiver, I am creating lists on the site and adding fields to them.
One of the fields I am creating is a choice field (drop-down list). I add several choice options to this control but find that when the site is created, if I drop down the field there are no options in the list. I realised, through web research, that I needed to call the update method of my choice field. As soon as I did this, the creation of the site threw an exception with the following description: 0x80070057 Not very helpful.
If I comment out the update method of the choice field the site creates again no problem, but there are no options in the drop-down.
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();
I also include this field in the default view.
SPView defaultView = newList.DefaultView; defaultView.ViewFields.Add(newList.Fields.GetField(Constants.FIELD_TRANSMITTAL_STATUS));