CSS stylesheets


List of examples:

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);


> Back to list of examples

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);
}


> Back to list of examples

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);
}


> Back to list of examples

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);
}


> Back to list of examples

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);
}


> Back to list of examples

Deleting a CSS stylesheet




// Gets the CSS stylesheet
CssStylesheetInfo deleteStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("NewStylesheet");

// Deletes the CSS stylesheet
CssStylesheetInfoProvider.DeleteCssStylesheetInfo(deleteStylesheet);


> Back to list of examples