【问题标题】:AfterProperties and BeforeProperties in managedmetadata fields returns different strings depending on languagemanagedmetadata 字段中的 AfterProperties 和 BeforeProperties 根据语言返回不同的字符串
【发布时间】:2012-10-30 22:48:48
【问题描述】:

我在列表中有一个托管元数据列。英文值:Brussel 法文:Bruxelles。

我需要在 ItemUpdating 事件中比较 before 和 after 属性。我知道之前不能使用,因为它会在项目更新中返回 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;
        }

【问题讨论】:

    标签: c# sharepoint sharepoint-2010


    【解决方案1】:

    我是这样解决的。 关于它的博客: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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-12
      • 2015-04-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-16
      • 2016-11-04
      • 1970-01-01
      相关资源
      最近更新 更多