Use code to Configure a SharePoint Site (Configure SharePoint Site programmatically)

Source: Internet
Author: User

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.

  1. 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 Settings

    public 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.