Kentico CMS 7.0 Developer's Guide

Managing CSS stylesheets

Managing CSS stylesheets

Previous topic Next topic Mail us feedback on this topic!  

Managing CSS stylesheets

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a CSS stylesheet.

 

private void CreateCssStylesheet()
{
  // Create new css stylesheet object
  CssStylesheetInfo newStylesheet = new CssStylesheetInfo();

 
  // Set the properties
   newStylesheet.StylesheetDisplayName = "My new stylesheet";
   newStylesheet.StylesheetName = "MyNewStylesheet";
   newStylesheet.StylesheetText = "Some CSS code";

 
  // Save the css stylesheet
  CssStylesheetInfoProvider.SetCssStylesheetInfo(newStylesheet);
}

 

The following example gets and updates a stylesheet.

 

private bool GetAndUpdateCssStylesheet()
{
  // Get the css stylesheet
  CssStylesheetInfo updateStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewStylesheet");
  if (updateStylesheet != null)
   {
      // Update the properties
       updateStylesheet.StylesheetDisplayName = updateStylesheet.StylesheetDisplayName.ToLower();

 
      // Save the changes
      CssStylesheetInfoProvider.SetCssStylesheetInfo(updateStylesheet);

 
      return true;
   }

 
  return false;
}

 

The following example gets and bulk updates stylesheets.

 

private bool GetAndBulkUpdateCssStylesheets()
{
  // Prepare the parameters
  string where = "StylesheetName LIKE N'MyNewStylesheet%'";

 
  // Get the data
  DataSet stylesheets = CssStylesheetInfoProvider.GetCssStylesheets(where, null);
  if (!DataHelper.DataSourceIsEmpty(stylesheets))
   {
      // Loop through the individual items
      foreach (DataRow stylesheetDr in stylesheets.Tables[0].Rows)
       {
          // Create object from DataRow
          CssStylesheetInfo modifyStylesheet = new CssStylesheetInfo(stylesheetDr);

 
          // Update the properties
           modifyStylesheet.StylesheetDisplayName = modifyStylesheet.StylesheetDisplayName.ToUpper();

 
          // Save the changes
          CssStylesheetInfoProvider.SetCssStylesheetInfo(modifyStylesheet);
       }

 
      return true;
   }

 
  return false;
}

 

The following example deletes a stylesheet.

 

private bool DeleteCssStylesheet()
{
  // Get the css stylesheet
  CssStylesheetInfo deleteStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewStylesheet");

 
  // Delete the css stylesheet
  CssStylesheetInfoProvider.DeleteCssStylesheetInfo(deleteStylesheet);

 
  return (deleteStylesheet != null);
}