CSS stylesheets
List of examples:
- Creating a new CSS stylesheet
- Updating a CSS stylesheet
- Updating multiple CSS stylesheets
- Assigning a CSS stylesheet to a site
- Removing a CSS stylesheet from a site
- Deleting a CSS stylesheet
Creating a new CSS stylesheet
// Creates a new CSS stylesheet object
CssStylesheetInfo newStylesheet = new CssStylesheetInfo();
// Sets the stylesheet properties
newStylesheet.StylesheetDisplayName = "New stylesheet";
newStylesheet.StylesheetName = "NewStylesheet";
newStylesheet.StylesheetText = "CSS code";
// Saves the CSS stylesheet to the database
CssStylesheetInfoProvider.SetCssStylesheetInfo(newStylesheet);
Updating a CSS stylesheet
// Gets the CSS stylesheet
CssStylesheetInfo updateStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("NewStylesheet");
if (updateStylesheet != null)
{
// Updates the stylesheet properties
updateStylesheet.StylesheetDisplayName = updateStylesheet.StylesheetDisplayName.ToLower();
// Saves the changes to the database
CssStylesheetInfoProvider.SetCssStylesheetInfo(updateStylesheet);
}
Updating multiple CSS stylesheets
// Gets all CSS stylesheets whose name starts with 'NewStylesheet'
var stylesheets = CssStylesheetInfoProvider.GetCssStylesheets().WhereStartsWith("StylesheetName", "NewStylesheet");
// Loops through individual stylesheets
foreach (CssStylesheetInfo stylesheet in stylesheets)
{
// Updates the stylesheet properties
stylesheet.StylesheetDisplayName = stylesheet.StylesheetDisplayName.ToUpper();
// Saves the changes to the database
CssStylesheetInfoProvider.SetCssStylesheetInfo(stylesheet);
}
Assigning a CSS stylesheet to a site
// Gets the CSS stylesheet
CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("NewStylesheet");
if (stylesheet != null)
{
// Assigns the stylesheet to the current site
CssStylesheetSiteInfoProvider.AddCssStylesheetToSite(stylesheet.StylesheetID, SiteContext.CurrentSiteID);
}
Removing a CSS stylesheet from a site
// Gets the CSS stylesheet
CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("NewStylesheet");
if (stylesheet != null)
{
// Gets the binding object representing the relationship between the stylesheet and the current site
CssStylesheetSiteInfo stylesheetSite = CssStylesheetSiteInfoProvider.GetCssStylesheetSiteInfo(stylesheet.StylesheetID, SiteContext.CurrentSiteID);
// Removes the stylesheet from the current site
CssStylesheetSiteInfoProvider.DeleteCssStylesheetSiteInfo(stylesheetSite);
}
Deleting a CSS stylesheet
// Gets the CSS stylesheet
CssStylesheetInfo deleteStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("NewStylesheet");
// Deletes the CSS stylesheet
CssStylesheetInfoProvider.DeleteCssStylesheetInfo(deleteStylesheet);