SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a custom master page with a custom CSS file, being deployed in a feature form VS2010. I'm using the CssRegistation control to add the new CSS, but whenever I try to load a page that uses it, I get an "Illegal characters in path" exception. Which is odd, because there aren't any illegal characters that I can see in the path.

The code I'm using to add the CSS to the page looks like this (from MSDN):

<SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/myfolder/mystyle.css %>"  After="corev4.css" runat="server"/>

I've check the relevant galleries and the master page is deploying correctly to _layouts/masterpage/mymaster.master, and the CSS is deploying correctly to Style Library/myfolder/mystyle.css.

What have I missed?

share|improve this question

Have you tried changing "Style Library" to "Style%20Library"?

share|improve this answer
Doesn't work - '%' is an illegal character when explicitly declared in the path. – Mourndark Jun 27 '12 at 7:35
Shot in the dark. – RJ Cuthbertson Jun 27 '12 at 17:47
up vote 1 down vote accepted

I'm an idiot. The error was coming from an old CssRegistration control that I hadn't commented out properly...

share|improve this answer
Happens to the best of us. – RJ Cuthbertson Jun 27 '12 at 17:47

According to this blog post, you will have that issue if you are using SharePoint Foundation: In SPF you need to hard code the URL.

share|improve this answer
Yes that's right. The <% $SPUrl ~sitecollection token is part of the Publishing Infrastructure which is not available in SharePoint Foundation. But did @Moray mention that he/she is using foundation? – Vardhaman Deshpande Jun 26 '12 at 15:49
I'm using SharePoint Standard. – Mourndark Jun 27 '12 at 7:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.