通过代码配置SharePoint 站点 (Configure SharePoint Site programmatically)
平时在创建站点之后,我们都是通过人工对站点的设置,比如设置站点搜索,Document Id规则,导航条,还有比如设置文档库的版本控制,导航,content Type,以及自动创建文档库的视图,闲来无聊我们就通过代码帮助我们做这些事情。
- 搜索配置
a. 手工配置
b. 代码配置设置搜索public static void ApplySearchSetting(this SPWeb web) { #region Site Collection Search Dropdown Mode //<option selected="selected" value="HideScopeDD_DefaultContextual">Do not show scopes dropdown, and default to contextual scope</option> // <option value="HideScopeDD">Do not show scopes dropdown, and default to target results page</option> //<option value="ShowDD">Show scopes dropdown</option> //<option value="ShowDD_DefaultURL">Show, and default to 's' URL parameter</option> //<option value="ShowDD_DefaultContextual">Show and default to contextual scope</option> //<option value="ShowDD_NoContextual">Show, do not include contextual scopes</option> //<option value="ShowDD_NoContextual_DefaultURL">Show, do not include contextual scopes, and default to 's' URL parameter</option> #endregion try { web.AllProperties["SRCH_SITE_DROPDOWN_MODE"] = "ShowDD_DefaultContextual"; web.Update(); } catch (Exception ex) { } }
2. Document ID 服务
a. 手工配置
SIte Actions -->Site Settings -> Document ID Settings:
b. 代码配置
Document ID Settingspublic static void ApplyDocumentIDSetting(this SPWeb web, string siteId) { try { web.Properties["docid_settings_ui"] = "<?xml version=\"1.0\" encoding=\"utf-16\"?><DocIdUiSettings xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Prefix>" + siteId + "</Prefix><AssignmentEnabled>true</AssignmentEnabled></DocIdUiSettings>"; web.AllProperties["docid_settings_ui"] = "<?xml version=\"1.0\" encoding=\"utf-16\"?><DocIdUiSettings xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Prefix>" + siteId + "</Prefix><AssignmentEnabled>true</AssignmentEnabled></DocIdUiSettings>"; web.Update(); } catch (Exception ex) { } }
3. 站点导航条
a. 手工配置 (使用父站点的配置,并显示子站点)
b. 代码配置 (唯一要注意的是,要判断是否是RootWeb,如果是:只配置“显示子站点”的选项。
Navigationpublic static void ApplyNavigationSetting(this SPWeb web) { try { if(!web.IsRootWeb) web.Navigation.UseShared = true; //show subsites #region PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web); // Global Navigation //Show Subsites publishingWeb.Navigation.GlobalIncludeSubSites = true; //Show Pages publishingWeb.Navigation.GlobalIncludePages = false; // Maximum number of dynamic items to show within this level of navigation: //publishingWeb.Navigation.GlobalDynamicChildLimit = 60; //Update the changes publishingWeb.Update(); #endregion } catch (Exception ex) { } }
下一篇分享如果通过代码设置Document Library的配置。