API Questions on Kentico API.
Version 6.x > API > Set Site CSS stylesheet programmatically ? View modes: 
User avatar
Member
Member
changchang500-hotmail - 10/29/2012 3:40:27 AM
   
Set Site CSS stylesheet programmatically ?
Hi all,

I'm trying to figure out a way to set "Site CSS stylesheet" (the dropdown list under Site manager->Sites->General) in code. I tried following code but stylesheetSite always returns null for some reason. Thanks for any help.

CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo(a_styleSheetName);
if (stylesheet != null)
{
int siteId = CMSContext.CurrentSiteID;
CssStylesheetSiteInfo stylesheetSite = CssStylesheetSiteInfoProvider.GetCssStylesheetSiteInfo(stylesheet.StylesheetID, siteId);
CssStylesheetSiteInfoProvider.SetCssStylesheetSiteInfo(stylesheetSite);
}

User avatar
Member
Member
davids-kentico - 10/29/2012 7:14:13 AM
   
RE:Set Site CSS stylesheet programmatically ?
Hi, the following two snippets should do the trick

To get the default stylesheet that belongs to the Corporate Site:
SiteInfo site = SiteInfoProvider.GetSiteInfo("CorporateSite");

if (site != null)
{
CssStylesheetInfo css = CssStylesheetInfoProvider.GetCssStylesheetInfo(site.SiteDefaultStylesheetID);

}


To change the stylesheet for Corporate site:

CssStylesheetInfo newCss = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewCSS");

if (newCss != null)
{
SiteInfo site = SiteInfoProvider.GetSiteInfo("CorporateSite");

if (site != null)
{
site.SiteDefaultStylesheetID = newCss.StylesheetID;
SiteInfoProvider.SetSiteInfo(site);
}
}

User avatar
Member
Member
changchang500-hotmail - 10/29/2012 8:38:57 PM
   
RE:Set Site CSS stylesheet programmatically ?
Thanks, it works great.