2

リストに管理されたメタデータ列があります。英語の値:フランス語のブリュッセル: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;
        }
4

1 に答える 1

1

このように修正しました。ithereについてのブログ:http://levalencia.wordpress.com/

string currentBudgetSection = properties.ListItem["BudgetSection"] == null ? string.Empty : properties.ListItem.GetTaxonomyFieldValueByLanguage(item.Web.Site, "BudgetSection", Thread.CurrentThread.CurrentUICulture.LCID).ToString();
            string newBudgetSection=string.Empty ;
            if (properties.AfterProperties["BudgetSection"] != null && !string.IsNullOrEmpty(properties.AfterProperties["BudgetSection"].ToString()))
            {
                 int startIndex = properties.AfterProperties["BudgetSection"].ToString().IndexOf("#")+1;
                 int endIndex = properties.AfterProperties["BudgetSection"].ToString().IndexOf("|");
                 int length = endIndex - startIndex;
                 newBudgetSection = properties.AfterProperties["BudgetSection"] == null ? string.Empty : properties.AfterProperties["BudgetSection"].ToString().Substring(startIndex, length);
            }


 bool budgetSectionSame = newBudgetSection.Equals(currentBudgetSection);
            if((!budgetSectionSame )
//do something
于 2012-10-30T14:48:48.847 に答える