I have a custom ASPX
page where the user inputs data and clicks Save to add new item to the list. The field My Department
is a Managed Metadata field
(single choice). The user sets the value for this field through TaxonomyWebTaggingControl
control. The problem happens when the value is supposed to be set to the new list item:
string departmentField = "My_x0020_Department"; //internal field name
SPListItem item = myList.Items.Add();
item[SPBuiltInFieldId.Title] = this.documentTitleTextBox.Text;
item[departmentField] = this.DepartmentTaxonomy.Text; //error fires here
item.Update();
The error is ArgumentException: Value does not fall within the expected range.
If the user does not specify the value for the department, i.e. if this.DepartmentTaxonomy.Text = string.Empty;
then there is no error.