Updating website properties

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following example shows you how to modify website properties in your code:

 

[C#]

 

using CMS.CMSHelper;

using CMS.SiteProvider;

using CMS.WorkflowEngine;

 

...

 

        // Get current site name (you can use code name of the required site instead)

        string siteName = CMSContext.CurrentSiteName;

 

        // Check if the site name is available

        if (siteName != null)

        {

            try

            {

                // Stop the site because we will change the domain of the site

                SiteInfoProvider.StopSite(siteName);

 

                // Get site info

                SiteInfo si = SiteInfoProvider.GetSiteInfo(siteName);

 

                if (si != null)

                {

                    si.DisplayName = "New display name";

                    si.Description = "New description";

 

                    // Change domain of the site

                    si.DomainName = "mynewdomain.com";

 

                    // Set new domain alias with default content language set to en-US

                    SiteInfoProvider.AddDomainAlias(siteName, "newdomainalias""en-US");

 

                    // Save the changes

                    SiteInfoProvider.SetSiteInfo(si);

                }

 

                // Run the site

                SiteInfoProvider.RunSite(siteName);

 

                lblInfo.Text = string.Format("Site '{0}' has been edited.", siteName);

            }

            catch (RunningSiteException ex)

            {

                lblError.Text = "Site cannot be started.<br />Original exception: " + ex.Message;

            }

            catch (Exception ex)

            {

                lblError.Text = "Error when modifying site properties.<br />Original exception: " + ex.Message;

            }

        }

 

The following sample code shows how you can add a new content culture to an existing website:

 

[C#]

 

using CMS.SiteProvider;

 

...

     

        // Get site and culture objects

        SiteInfo si = SiteInfoProvider.GetSiteInfo("CorporateSiteASPX");

        CultureInfo ci = CultureInfoProvider.GetCultureInfo("AR-Sa");

 

        // If both exists

        if ((si != null) && (ci != null))

        {

            // Add culture to site

            CultureSiteInfoProvider.AddCultureToSite(ci.CultureID, si.SiteID);

        }

 

The following sample code shows how you can add a new domain alias to an existing website:

 

[C#]

 

using CMS.SiteProvider;

 

...

 

        // Get site object by site code name

        SiteInfo si = SiteInfoProvider.GetSiteInfo("CorporateSiteASPX");

 

        // If site exists

        if (si != null)

        {

            // Create new domain alias object

            SiteDomainAliasInfo sdai = new SiteDomainAliasInfo();

 

            // Set properties

            sdai.SiteDomainAliasName = "127.0.0.1";

            sdai.SiteID = si.SiteID;

 

            // Save to database

            SiteDomainAliasInfoProvider.SetSiteDomainAliasInfo(sdai);

        }

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?update_web_site_properties.htm