After creating a site, we usually set the site manually, such as setting site search, Document Id rules, navigation bars, and setting Document library version control, navigation, content Type, and automatically create the view of the document library. If you are bored, you can use the code to help us do these things.
- Search Configuration
A. Manual Configuration
B. Code Configuration
Set search 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 service
A. Manual Configuration
SIte Actions --> Site Settings-> Document ID Settings:
B. Code Configuration
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.Site navigation bar
A. Manual configuration (use the configuration of the parent site and display the child site points)
B. Code configuration (the only thing to note is whether it is RootWeb. If yes, only the "show sub-site" option is configured.
Navigation public 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) { } }
The next article explains how to configure Document Library through code.