Kentico CMS 7.0 Developer's Guide

Updating website properties

Updating website properties

Previous topic Next topic Mail us feedback on this topic!  

Updating website properties

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

The following example shows you how to modify website properties using the API:

 

[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";
 
                // 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("CorporateSite");

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

 

        // If both exists

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

        {

            // Add culture to site

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

        }