privatevoid CreateSite() { // Create new site object SiteInfo newSite = newSiteInfo();
// Set the properties newSite.DisplayName = "My new site"; newSite.SiteName = "MyNewSite"; newSite.Status = SiteStatusEnum.Stopped; newSite.DomainName = "127.0.0.1";
// Save the site SiteInfoProvider.SetSiteInfo(newSite); }
The following example gets and updates a site.
privatebool GetAndUpdateSite() { // Get the site SiteInfo updateSite = SiteInfoProvider.GetSiteInfo("MyNewSite"); if (updateSite != null) { // Update the properties updateSite.DisplayName = updateSite.DisplayName.ToLower();
// Save the changes SiteInfoProvider.SetSiteInfo(updateSite);
returntrue; }
returnfalse; }
The following example gets and bulk updates sites.
privatebool GetAndBulkUpdateSites() { // Prepare the parameters string where = "SiteName LIKE N'MyNewSite%'";
// Get the data DataSet sites = SiteInfoProvider.GetSites(where, null); if (!DataHelper.DataSourceIsEmpty(sites)) { // Loop through the individual items foreach (DataRow siteDr in sites.Tables[0].Rows) { // Create object from DataRow SiteInfo modifySite = newSiteInfo(siteDr);
// Update the properties modifySite.DisplayName = modifySite.DisplayName.ToUpper();
// Save the changes SiteInfoProvider.SetSiteInfo(modifySite); }
returntrue; }
returnfalse; }
The following example deletes a site.
privatebool DeleteSite() { // Get the site SiteInfo deleteSite = SiteInfoProvider.GetSiteInfo("MyNewSite"); if (deleteSite != null) { TreeProvider treeProvider = newTreeProvider(CMSContext.CurrentUser); // Delete documents belonging under the site DocumentHelper.DeleteSiteTree("MyNewSite", treeProvider); // Delete the site SiteInfoProvider.DeleteSite(deleteSite); returntrue; } returnfalse; }