Sites


List of examples:

Sites

Creating a new site



// Creates a new site object
SiteInfo newSite = new SiteInfo();

// Sets the site properties
newSite.DisplayName = "New site";
newSite.SiteName = "NewSite";
newSite.Status = SiteStatusEnum.Stopped;
newSite.DomainName = "127.0.0.1";

// Saves the site to the database
SiteInfo.Provider.Set(newSite);

> Back to list of examples

Updating a site



// Gets the site
SiteInfo updateSite = SiteInfo.Provider.Get("NewSite");
if (updateSite != null)
{
    // Updates the site properties
    updateSite.DisplayName = updateSite.DisplayName.ToLower();

    // Saves the modified site to the database
    SiteInfo.Provider.Set(updateSite);
}

> Back to list of examples

Updating multiple sites



// Gets all sites whose code name starts with 'New'
var sites = SiteInfo.Provider.Get().WhereStartsWith("SiteName", "New");

// Loops through individual sites
foreach (SiteInfo site in sites)
{
    // Updates the site properties
    site.DisplayName = site.DisplayName.ToUpper();

    // Saves the modified site to the database
    SiteInfo.Provider.Set(site);
}

> Back to list of examples

Assigning a culture to a site



// Gets the site and culture objects
SiteInfo site = SiteInfo.Provider.Get("NewSite");
CultureInfo culture = CultureInfo.Provider.Get("ar-sa");

if ((site != null) && (culture != null))
{
    // Assigns the culture to the site
    CultureSiteInfo.Provider.Add(culture.CultureID, site.SiteID);
}

> Back to list of examples

Removing a culture from a site



// Gets the site and culture objects
SiteInfo site = SiteInfo.Provider.Get("NewSite");
CultureInfo culture = CultureInfo.Provider.Get("ar-sa");

if ((site != null) && (culture != null))
{
    // Removes the culture from the site
    CultureSiteInfo.Provider.Remove(culture.CultureID, site.SiteID);
}

> Back to list of examples

Adding a domain alias to a site



// Gets the site object
SiteInfo site = SiteInfo.Provider.Get("NewSite");

if (site != null)
{
    // Creates a new site domain alias object
    SiteDomainAliasInfo newAlias = new SiteDomainAliasInfo(SiteDomainAliasInfo.OBJECT_TYPE);                    
    newAlias.SiteDomainAliasName = "127.0.0.1";
    
    // Assigns the domain alias to the site
    newAlias.SiteID = site.SiteID;

    // Saves the site domain alias to the database
    SiteDomainAliasInfo.Provider.Set(newAlias);
}

> Back to list of examples

Deleting a site’s domain alias



// Gets the site object
SiteInfo site = SiteInfo.Provider.Get("NewSite");

if (site != null)
{
    // Gets the specified domain alias for the site
    SiteDomainAliasInfo deleteAlias = SiteDomainAliasInfo.Provider.Get()
        .TopN(1)
        .WhereEquals("SiteDomainAliasName", "127.0.0.1")
        .WhereEquals("SiteID", site.SiteID)
        .FirstOrDefault();

    // Deletes the site domain alias
    SiteDomainAliasInfo.Provider.Delete(deleteAlias);
}

> Back to list of examples

Deleting a site



// Gets the site
SiteInfo deleteSite = SiteInfo.Provider.Get("NewSite");

if (deleteSite != null)
{
    // Deletes the site
    SiteInfo.Provider.Delete(deleteSite);
}

> Back to list of examples

Site actions

Starting a site



// Gets the site
SiteInfo site = SiteInfo.Provider.Get("NewSite");
if (site != null)
{
    // Starts the site
    SiteInfoProvider.RunSite(site.SiteName);
}

> Back to list of examples

Stopping a site



// Gets the site
SiteInfo site = SiteInfo.Provider.Get("NewSite");
if (site != null)
{
    // Stops the site
    SiteInfoProvider.StopSite(site.SiteName);
}

> Back to list of examples