I want to assign a taxonomy field value to the user profile property which is fetched from ListItem. The taxonomy field is single selection valued.
The user profile property name is: Dept
.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPListItem item = properties.ListItem;
string url = Convert.ToString(item[FieldNames.DepartmentUrl]);
string title = Convert.ToString(item[FieldNames.DepartmentTitle]);
string desc = Convert.ToString(item[FieldNames.DepartmentDescription]);
//SPWeb newWeb = properties.Web.Webs.Add(url,title,desc,1033,Webs.Department.WebTempalate,false,false);
List<string> nativeMembers = new List<string>();
SPFieldUserValueCollection nMembers = (SPFieldUserValueCollection)item["oiplbNativeMembers"];
foreach (SPFieldUserValue field in nMembers)
{
SPUser user = field.User;
nativeMembers.Add(user.LoginName);
}
var taxonomyField = item.Fields.GetFieldByInternalName(FieldNames.Department) as TaxonomyField;
if (taxonomyField.AllowMultipleValues)
{
}
else
{
var fieldValue = item[taxonomyField.Title] as TaxonomyFieldValue;
var fieldValue = item[taxonomyField.Title] as TaxonomyFieldValue;
SPServiceContext contex = SPServiceContext.GetContext(properties.Site);
UserProfileManager upm = new UserProfileManager(contex);
UserProfile up = upm.GetUserProfile(nativeMembers[0]);
up["Dept"].Value = fieldValue.Label;
up.Commit();
}
});
I am stuck by reaching the specific stage and don't know what do? I debugged the program and found that var fieldvalue
is assigned taxonomy value successfully.
Please help.