Todd Bleeker's 12 Hive

All MindsharpBlogs

Are you pondering what I'm pondering?

My Links

Post Categories

Archives

Blog Stats

My saga with the ONET.XML Project element's AlternateCSS attribute

We are repeatedly warned in the Windows SharePoint Services (WSS) SDK not to alter the files in the 60 Hive, including the built-in ows.css file. To customize our sites, it would be helpful if we had our own Cascading Style Sheet (CSS) file that we could use to override the CSS classes that WSS uses to display pages. The file could contain alterations to the CSS classes WSS has already defined and include our own CSS classes without worry about service patches or patches overwriting our changes. However, this isn't as easy as it should be and there are lots of pits to avoid. I've documented them below.

First, the WSS SDK states:

Warning: Changes made to OWS.CSS may be lost when Windows SharePoint Services is updated, such as through installation of service packs or patches. An alternate .css file can be specified in the ONET.XML file of a site definition by using the AlternateCSS attribute of the Project element.

[AlternateCSS is] used in an ONET.XML file to specify the name of an alternate CSS file located in the Local_Drive:\Microsoft Shared\Web Server Extensions\60\TEMPLATE\LAYOUTS\1033\STYLES directory that defines styles to use in the site definition.

So, the AlternateCSS attribute sounds like something we should implement on all Site Definitions, even if we don't immediately need it. Otherwise, sites that we create between now and when we do implement this attribute won't retroactively benefit from future style changes.

Since CSS styles cascade, I _thought_ that this attribute would leave the existing ows.css styles in place and I would simply have to override the styles that I wanted to alter and add the CSS classes that I wanted to add. Unfortunately, I discovered that I had to completely copy all the built-in styles into my alternate CSS file. This means that if the WSS team changes the styles in the ows.css file in the future, my sites won't reflect those style changes. I will have to manually copy the changes into my alternate CSS file. This will likely be a very rare occurrence, so I determined that the benefit outweighed the redundancy.

I initially created a copy of the ows.css file called mindsharp.css and placed it into the 60 Hive's ..\60\TEMPLATE\LAYOUTS\1033\STYLES subdirectory along-side the ows.css file. The SDK incorrectly instructs that it should go there (more about this momentarily). I altered the .ms-bannerframe class so that I could easily see the effect in the top nav of any site.

I then added the AlternateCSS attribute to the Project element in a copy of the STS Site Definition's ONET.XML file as follows:
<Project Title="Team Web Site"
         ListDir="Lists"
         xmlns:ows="Microsoft SharePoint"
         AlternateCSS="mindsharp.css">
 
  CAML  

After an iisreset, I created and subsequently templatized a new WSS site using my altered Site Definition hoping that was all there was to it. However, when I saw the Home page, I was disappointed. I saw no visible effect. In fact, the only pages in the site that looked different were the administrative pages in /_layouts/1033 (AKA direct mode pages), and those pages didn't appear to have any style applied to them at all! This wasn't what I expected and obviously was an undesirable effect.

After some investigative research, I discovered that if I put the mindsharp.css file into the /_layouts/1033 directory rather than the /_layouts/1033/Styles directory (as the SDK suggested), the administrative pages began reflecting my style change. However, I don't like to put files into the /_layouts/1033 directory. I have an /_layouts/1033/Custom directory where I typically put my custom files. So, I moved the mindsharp.css file into the 60 Hive's ..\60\TEMPLATE\LAYOUTS\1033\Custom directory, renamed mindsharp.css to ows.css (so I'd know what file I was customizing), and changed the AlternateCSS attribute as follows:
<Project Title="Team Web Site"
         ListDir="Lists"
         xmlns:ows="Microsoft SharePoint"
         AlternateCSS="Custom/ows.css">
 
  CAML  

Of course, I had to reset IIS, create a new WSS site, and templatize it using my altered Site Definition again. After that, the administrative pages DID reflect my style change but the site pages still did NOT reflect my style change.

Rats, more research. What I subsequently discovered is very unfortunate, but can be overcome.

The administrative pages use the following server control to include either the ows.css file OR the Site Definition defined AlternateCSS file (note that the DefaultUrl is a page relative reference):
<SharePoint:CssLink DefaultUrl="styles/ows.css" runat="server"/>
 
  ASPX  

Therefore, as previously noted, both CSS files are not included so we need to copy all the classes defined in the ows.css file into our alternate CSS file.

The site pages use the following HTML Link tag to include the ows.css file regardless of how the AlternateCSS attribute is defined (note how the LCID is dynamically included):
<Link REL="stylesheet" Type="text/css" HREF="/_layouts/<%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%>/styles/ows.css">
 
  ASPX  

To continue, I would need to replace the Link tag on all the site pages in my Site Definition with the SharePoint:CssLink server control. I initially tested this with the default.aspx page to see how well this would work. I had to use a root relative DefaultUrl property on the SharePoint:CssLink server control as follows:
<SharePoint:CssLink DefaultUrl="/_layouts/1033/styles/ows.css" runat="server"/>
 
  ASPX  

I did try to dynamically resolve the LCID using the <%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%> server value in the DefaultUrl property but the string was escaped instead of being resolved. So, I hard coded the US English LCID, 1033, instead. While unfortunate, I didn't pursue an alternative because this will work for our implementation (of course, suggestions are welcome).

Once again, I tested this configuration. But once again, the default.aspx page did not find the alternate CSS file. This problem was finally resolved by also making the AlternateCSS attribute in the ONET.XML file root relative as follows:
<Project Title="Team Web Site"
         ListDir="Lists"
         xmlns:ows="Microsoft SharePoint"
         AlternateCSS="/_layouts/<%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%>/Custom/ows.css"
>
 
  CAML  

Finally, in each of the other roughly 100 files in the Site Definition (mostly in the LISTS folder), I replaced the HTML Link tag to the root relative version of the SharePoint:CssLink server control. I left the administrative direct mode pages with a page relative SharePoint:CssLink server control since it does work for pages in /_layouts/1033 and we are warned not to modify those files either. And after a final iisreset, ALL changes to my ..\60\TEMPLATE\LAYOUTS\1033\Custom\ows.css file were instantly reflected across all site and administrative pages throughout the entire site. I tested it on both top-level sites and child sites.

In summary, using the AlternateCSS attribute is possible (if inaccurately documented), but it requires a minor alteration to every ASPX page in the Site Definition. This is just one more example where the use of root relative WSS references would be very helpful. Also, the alternate CSS file must include a redundant copy of every CSS class defined in the ows.css file. While I would still recommend using this feature in all WSS Site Definitions, it isn't as easy to do as I'd hoped.

Tasks required to implement this solution:

  1. Create a Custom directory in the 60 Hive's ..\60\TEMPLATE\LAYOUTS\1033 directory.

  2. Copy the ows.css file into the Custom directory.

  3. Create a custom Site Definition with related WEBTEMP configurations (it's strongly recommended you don't alter the built-in SharePoint Team Site (STS) or Multi-Page Site (MPS) Site Definitions).
  4. Add a root relative AlternateCSS attribute in your custom Site Definition's ONET.XML file as follows:
    <Project Title="Team Web Site"
             ListDir="Lists"
             xmlns:ows="Microsoft SharePoint"
             AlternateCSS="/_layouts/<%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%>/Custom/ows.css"
    >
     
      CAML  

  5. Replace the HTML Link tag with the SharePoint:CssLink server control in all ASPX pages in all directories of your custom Site Definition.
    Replace this (near the top of each file):
    <Link REL="stylesheet" Type="text/css" HREF="/_layouts/<%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%>/styles/ows.css">
     
      ASPX  

    With this:
    <SharePoint:CssLink DefaultUrl="/_layouts/1033/styles/ows.css" runat="server"/>
     
      ASPX  

  6. Create a new site using your custom Site Definition and any changes that you make to the ows.css in the Custom directory will reflect on all pages in your new site.

<Todd />

posted on Monday, February 28, 2005 4:05 PM

Feedback

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 3/2/2005 9:36 AM Derek

Thanks Todd, works great!

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 3/3/2005 11:21 AM Todd Bleeker

Thanks Aaron. By following these steps, all pages respect the AlternateCSS attribute including the administrative pages in /_layouts/1033.

<Todd />

# More remarks about 6/10/2005 8:45 AM Stramit's SharePoint Blog

# The wonderful world of Site Definitions 7/6/2005 11:19 AM Graphical Wonder

I'm still here ... and I am still going to put the rest of the tutorial of site creation up really soon! It's been very warm, and i've been busy. This post is just to send a link which I've...

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 2/22/2006 5:16 AM Samata Upadrasta

Hi,
I have a Sharepoint team site, which has a custom webpart. Custom webpart have a link which opens a custom .aspx page. ASPX page is placed in LAYOUTS\1033 folder. When a user who got permissions on the team site and WHO DOES NOT HAVE PERMISSIONS ON PORTAL SITE tries to open this .aspx file, ACCESS IS DENIED error is occured. The reason being the user not having permission on the LAYOUT/1033 folder as he does not have permissions on the sharepoint portal. Can anyone suggest solution for this problem?

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 3/4/2008 3:16 PM Atlanta Real Estate Listings

I am kind of new at this, but why not touch the built-in ows.css file? It seems like it would be harmless enough.

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 5/31/2008 9:37 AM Youtube

This is just great!

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 6/2/2008 6:07 AM Kız Oyunları

Can anyone suggest solution for this problem.
http://www.futboloyunlari.org
http://www.araba-oyunlari.com
http://www.arabaresim.net

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 6/5/2008 5:37 AM Youtube

This is just great!

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 6/19/2008 1:56 AM Youtube

very nice article

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 7/3/2008 7:11 PM izlesene

http://www.trabzonforum.com/
http://www.youtubeizlesenetr.com/

# Forum 7/21/2008 5:27 PM Forum

Thanks

# re: Forum 7/21/2008 5:28 PM Forum

Thank you my friend..

# re: Chat 7/21/2008 5:29 PM Chat

Thank you my friend..

# re: Mirc Mic İndir 7/22/2008 9:23 AM mircalem

thanks.

# re: çet cet chat 7/22/2008 9:23 AM çet

thanks.

# re: İzlesene youtube 7/22/2008 9:24 AM youtube

thanks.

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 4:34 AM güvenlik kıyafeti

thanks you very nice web page wonderful page

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:02 AM Çizgi Film

thanks very web page

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:02 AM Reklam Ajans

thanks you web page wonderful

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:09 AM web tasarım

thank you very page wonderful very good nice see you

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:09 AM film izle

thank you very nice see you beatfiul

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:10 AM Gelinlikler

thank you very nice web page wonderful

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:10 AM masaüstü resimleri

wonderful web page see you thank you

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:11 AM Mercedes Yedek Parçaları

thank you very nice web page wonderful

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:12 AM autocad kursu

beatiful wonderful web page nice see you web posted

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:25 AM Müzik Dinle

thanks very good

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:26 AM Havuz

very good

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:27 AM Reseller

very good

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:27 AM yemek tarifleri

very good

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:28 AM havuz

very good

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:29 AM film izle

very good

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:31 AM otobüs firmaları

very good

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/5/2008 6:33 AM rüya tabiri

very good

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/8/2008 3:46 AM ilahi dinle

very good

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/8/2008 3:47 AM müzik dinle

very good

# re: My saga with the ONET.XML Project element's AlternateCSS attribute 8/8/2008 3:48 AM gaziosmanpaşa

very good

Title  
Name  
Url
CAPTCHA
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments