SharePoint 常用操作杂谈

前言

本文完全原创,转载请说明出处,希望对大家有用。

本篇博客是个人总结,一方面以便日后查看,另一方面希望能为其他人提供一些便利。

阅读目录

正文

  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;

            }

        }

 

你可能感兴趣的:(SharePoint)