リストに管理されたメタデータ列があります。英語の値:フランス語のブリュッセル:Bruxelles。
ItemUpdatingイベントで、プロパティの前後を比較する必要があります。beforeは、アイテムの更新時にnullを返すため、使用できないことを知っています。そのため、properties.ListItemを使用する必要があります。
ユーザーが英語のUIを使用している場合、用語は同じであるため、次のコードは正常に機能します。
ただし、ユーザーがフランス語を選択した場合、これは機能しません。afterpropertiesはBruxellesになるため
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;
}