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
SiteInfoProvider.SetSiteInfo(newSite);
Updating a site
// Gets the site
SiteInfo updateSite = SiteInfoProvider.GetSiteInfo("NewSite");
if (updateSite != null)
{
// Updates the site properties
updateSite.DisplayName = updateSite.DisplayName.ToLower();
// Saves the modified site to the database
SiteInfoProvider.SetSiteInfo(updateSite);
}
Updating multiple sites
// Gets all sites whose code name starts with 'New'
var sites = SiteInfoProvider.GetSites().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
SiteInfoProvider.SetSiteInfo(site);
}
Assigning a culture to a site
// Gets the site and culture objects
SiteInfo site = SiteInfoProvider.GetSiteInfo("NewSite");
CultureInfo culture = CultureInfoProvider.GetCultureInfo("ar-sa");
if ((site != null) && (culture != null))
{
// Assigns the culture to the site
CultureSiteInfoProvider.AddCultureToSite(culture.CultureID, site.SiteID);
}
Removing a culture from a site
// Gets the site and culture objects
SiteInfo site = SiteInfoProvider.GetSiteInfo("NewSite");
CultureInfo culture = CultureInfoProvider.GetCultureInfo("ar-sa");
if ((site != null) && (culture != null))
{
// Removes the culture from the site
CultureSiteInfoProvider.RemoveCultureFromSite(culture.CultureID, site.SiteID);
}
Adding a domain alias to a site
// Gets the site object
SiteInfo site = SiteInfoProvider.GetSiteInfo("NewSite");
if (site != null)
{
// Creates a new site domain alias object
SiteDomainAliasInfo newAlias = new SiteDomainAliasInfo();
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
SiteDomainAliasInfoProvider.SetSiteDomainAliasInfo(newAlias);
}
Deleting a site’s domain alias
// Gets the site object
SiteInfo site = SiteInfoProvider.GetSiteInfo("NewSite");
if (site != null)
{
// Gets the specified domain alias for the site
SiteDomainAliasInfo deleteAlias = SiteDomainAliasInfoProvider.GetSiteDomainAliasInfo("127.0.0.1", site.SiteID);
// Deletes the site domain alias
SiteDomainAliasInfoProvider.DeleteSiteDomainAliasInfo(deleteAlias);
}
Deleting a site
// Gets the site
SiteInfo deleteSite = SiteInfoProvider.GetSiteInfo("NewSite");
if (deleteSite != null)
{
// Gets a TreeProvider instance
TreeProvider treeProvider = new TreeProvider(MembershipContext.AuthenticatedUser);
// Deletes the pages that belong to the site
DocumentHelper.DeleteSiteTree(deleteSite.SiteName, treeProvider);
// Deletes the site
SiteInfoProvider.DeleteSite(deleteSite);
}
Site actions
Starting a site
// Gets the site
SiteInfo site = SiteInfoProvider.GetSiteInfo("NewSite");
if (site != null)
{
// Starts the site
SiteInfoProvider.RunSite(site.SiteName);
}
Stopping a site
// Gets the site
SiteInfo site = SiteInfoProvider.GetSiteInfo("NewSite");
if (site != null)
{
// Stops the site
SiteInfoProvider.StopSite(site.SiteName);
}