2
我在列表中有一个托管元数据列。用英语的数值:Brussel用法语:Bruxelles。managedmetadata字段中的AfterProperties和BeforeProperties根据语言返回不同的字符串
我需要在ItemUpdating事件中比较之前和之后的属性。我知道之前不能使用,因为它会在项目更新中返回null,所以我必须使用properties.ListItem。
如果用户使用英语的UI,那么下面的代码工作正常,因为术语是相同的。
但是,如果用户选择法语,那么这将无法正常工作。因为afterproperties将是布鲁塞尔
private void ValidateAssignmentDate(SPItemEventProperties properties, SPListItem item)
{
string currentBudgetSection = properties.ListItem["BudgetSection"] == null ? string.Empty : properties.ListItem.GetTaxonomyFieldValue("BudgetSection").ValidatedString.ToString();
string newBudgetSection = properties.AfterProperties["BudgetSection"].ToString();
bool budgetSectionSame = newBudgetSection.Equals(currentBudgetSection);
if(!budgetSectionSame))
{
//dosomething
他扩展方法是:(我不能改变的扩展方法)
public static TaxonomyFieldValue GetTaxonomyFieldValue(this SPListItem item, string fieldName)
{
TaxonomyFieldValue returnValue = null;
try
{
TaxonomyField taxonomyField = GetTaxonomyField(item, fieldName);
if (taxonomyField != null && taxonomyField.Id != null)
returnValue = item[taxonomyField.Id] as TaxonomyFieldValue;
}
catch (Exception ex)
{
throw;
}
return returnValue;
}