3
votes

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));
1

1 Answers

1
votes

Try to update the list before you call the update method of the field