代码之家  ›  专栏  ›  技术社区  ›  Brian Reischl

Sharepoint 2010-如何修改分类属性?

  •  1
  • Brian Reischl  · 技术社区  · 15 年前

    var property = profile[PropertyConstants.Interests];
    if (property != null)
    {
        property.Value = "sharepoint; stackoverflow; scotch";                    
    }
    

    但这带来了一个例外。

    5 回复  |  直到 15 年前
        1
  •  2
  •   Tom Vervoort    15 年前

    对于sharepoint2010我不知道,但是在2007年,profile[propertyName]是一个UserProfileValueCollection,所以它可以包含多个值。

    profile[PropertyConstants.Interests].Clear();
    profile[PropertyConstants.Interests].Add("sharepoint");
    profile[PropertyConstants.Interests].Add("stackoverflow");
    profile[PropertyConstants.Interests].Add("scotch");
    

    在2007年,您还需要调用userprofile上的Commit方法来保存对DB的更改。

        2
  •  1
  •   animuson    14 年前

    不知道它是否相关,但这里有一个快速和肮脏的方法:

    property.Value = new string[] {"sharepoint; stackoverflow; scotch"};
    

    很有魅力!清除以前的值并替换为字符串数组。

    尽管存在局限性/优势: 这样就不会遗漏重复项。如果因此要对“Value1”、“Value2”、“Value1”使用Add方法。保存的结果是“Value1;值2”。 使用新的string[]方法,它将保存所有三个字符串(我真的需要这种行为)。

        3
  •  1
  •   j0k gauthamp    13 年前
        internal void updateUserProfileExperienceTags(string psLabelGuidValuePairs, string psDomainUser)
        {
            try
            {
                System.Security.PermissionSet ps = new System.Security.PermissionSet
                (
                    System.Security.Permissions.PermissionState.Unrestricted
                );
                ps.Assert();
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPServiceContext serviceContext = SPServiceContext.Current;
                    UserProfileManager upm = new UserProfileManager(serviceContext);
                    ProfileSubtypePropertyManager pspm = upm.DefaultProfileSubtypeProperties;
                    UserProfile profile = upm.GetUserProfile(psDomainUser);
                    TaxonomyFieldValueCollection _TaxonomyFieldValueCollection = new TaxonomyFieldValueCollection(String.Empty);
                    _TaxonomyFieldValueCollection.PopulateFromLabelGuidPairs(psLabelGuidValuePairs);
                    TaxonomySession session = new TaxonomySession(SPContext.Current.Site);
                    TermStore termStore = session.TermStores["Managed Metadata Service"];
                    TermSetCollection termSets = termStore.GetTermSets("Technology", 1033);
                    TermSet sTerms = termSets[0];
                    profile["Skills-Experience"].Clear();
                    for (int ni = 0; ni < _TaxonomyFieldValueCollection.Count; ni++)
                    {
                        Guid guid = new Guid(_TaxonomyFieldValueCollection[ni].TermGuid);
                        Term sTerm = sTerms.GetTerm(guid);
                        profile["Skills-Experience"].AddTaxonomyTerm(sTerm);
                    }
                    profile.Commit();
                });
            }
            catch (Exception ex)
            {
                this.Controls.Add(new Literal() { Text = "updateUserProfileExperienceTags: " + ex.ToString() });
            }
            finally
            {
                System.Security.CodeAccessPermission.RevertAssert();
            }
        }
    

        4
  •  0
  •   Mark van Dijk    14 年前

    这并不是你问题的完整答案,但当我在寻找类似的东西并找到如何做到这一点时,我认为这对其他人来说可能也很有趣:

    • 添加分类系统项
    • 获取轴对称
    • 移除轴对称

    http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.userprofilevaluecollection_methods.aspx

    我想这是访问基于分类法的用户配置文件属性的“正确”方法。

        5
  •  -4
  •   Undo ptrk    11 年前

    试试这个:

    userprofile["propertyname"].Add(" ");
    
    userprofile["propertyname"].AddTaxonomyTerm(taxonomyterm);
    
    userprofile.Commit();