•SharePoint 2010 UserProfile 添加属性 •修改默认模板页 •Taxonomy字段绑定TermSet


  SharePoint 2010 UserProfile 添加属性

以下方法是为了将自定义属性添加到SharePoint UserProfile中

复制代码
   SPServiceContext context =SPServiceContext.GetContext(site);
   UserProfileConfigManager upcm = new UserProfileConfigManager(context);
   ProfilePropertyManager ppm = upcm.ProfilePropertyManager;
   CorePropertyManager cpm = ppm.GetCoreProperties();
   if (cpm.GetPropertyByName(name) == null)
   {
       CoreProperty cp = cpm.Create(false);
       cp.Name = name;
       cp.DisplayName = name;
       cp.Type = PropertyDataType.StringSingleValue;
       cp.Length = 100;
       cpm.Add(cp);
       ProfileTypePropertyManager ptpm =ppm.GetProfileTypeProperties(ProfileType.User);
       ProfileTypeProperty ptp = ptpm.Create(cp);
       ptpm.Add(ptp);
       ProfileSubtypeManager psm =ProfileSubtypeManager.Get(context);
       ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
       ProfileSubtypePropertyManager pspm = ps.Properties;
       ProfileSubtypeProperty psp = pspm.Create(ptp);
       psp.IsUserEditable = true;
       psp.PrivacyPolicy = PrivacyPolicy.OptIn;
       psp.DefaultPrivacy = Privacy.Organization;
       pspm.Add(psp);
   }
复制代码

如果需要新增的属性是一个Taxonomy类型的字段,则加入以下代码:

    TaxonomySession taxonomySession = new TaxonomySession(site);
       TermStore termStore = taxonomySession.DefaultSiteCollectionTermStore;
       Group group = termStore.Groups[your group name];
       TermSet termSet = group.TermSets[your Termset name];
       cp.TermSet = termSet;
  修改默认母板页

通常我们在发布自定义母板页的同时希望将站点默认模板页修改为自定义母板页

复制代码
     public void changeCustomMasterPage(SPWeb web, string masterpageurl,bool isCustomMasterPage)
        {
            SPFile newMasterPageFile = web.GetFile(master);
            if (newMasterPageFile.Exists)
            {
                if (isCustomMasterPage)
                    web.CustomMasterUrl = newMasterPageFile.ServerRelativeUrl;
                else
                    web.MasterUrl = newMasterPageFile.ServerRelativeUrl;
                web.Update();
            }
        }
复制代码
  Taxonomy字段绑定TermSet
复制代码
     public static void BindTermSet(TaxonomyField field, TermSet termSet, bool isPathRendered)
        {
            try
            {
                field.SspId = termSet.TermStore.Id;
                field.TermSetId = termSet.Id;
                field.TargetTemplate = string.Empty;
                field.AnchorId = Guid.Empty;
                field.IsPathRendered = isPathRendered;
                field.Update(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值