SharePoint 常用操作雜談

任澤華Ryan發表於2013-11-14

前言

本文完全原創,轉載請說明出處,希望對大家有用。

本篇部落格是個人總結,一方面以便日後檢視,另一方面希望能為其他人提供一些便利。

閱讀目錄

正文

 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;
            }
        }

  Query Author

<Where>
  <Eq>
    <FieldRef Name="Author" LookupId="True" />
    <Value Type="User">123</Value>
  </Eq>
</Where>

<Where>
  <Eq>
    <FieldRef Name="Author" LookupId="True" />
    <Value Type="Lookup">123</Value>
  </Eq>
</Where>

<Where>
  <Eq>
    <FieldRef Name="Author" />
    <Value Type="Integer">
      <UserID />
    </Value>
  </Eq>
</Where>

 

相關文章