The scenario

You have a bunch of CSS files stored in the Styles Library ofa site collection. Your masterpage references the CSS files in the style library using the following code:

<SharePoint:CSSRegistration name=”Style Library/myCSS.css” After=”corev4.css runat=”server”/>

Everything works fine so you decide to deploy the branding files to another site collection.

After applying the new masterpage, you get an error saying that the masterpage cannot find the CSS files referenced in the masterpage.

The reason for this is because the path defined in the CSSRegistration tag begins with /Style Library. This means that the masterpage will always try to look for the files in Library. To make it look for the files from the root of each site collection, you need to use the $SPUrl token in the file path.

<SharePoint:CSSRegistration name=”<% $SPUrl:~sitecollection/Style Library/myCSS.css %>” After=”corev4.css” runat=”server” />