I'm trying to add some css on my webpart for the first time in SP2010. But for some reason the css only works when you visit the site on the sharepoint server. I belive it's the href path because it only points on itself in the sharepoint server.

Path that only works on SP server:

<link type="text/css" rel="stylesheet" runat="server"
    href="C:\Users\Administrator\Desktop\Menu\Menu\Style\StylesheetGridMenu.css" />

I belive the code should look like this in my project but then nothing works:

<link type="text/css" rel="stylesheet" runat="server" href="/style/StylesheetGridMenu.css" />

Is there something I'm missing in the code?

  • Do you have provisioned the css file somewhere on the SharePoint server? – Hitodama Mar 19 '13 at 13:46

I had this very same issue yesterday...I would upload the CSS to the assets folder and reference it from there using the following code.

If you upload it anywhere else you run into the danger of certain users not having access to it. Here is the code to add the style sheet to the MasterPage, bit different from yours, just remember to change the path to suit yours...

<SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/NameOfSite/SiteAssets/yourcss.css %>" After="corev4.css" runat="server"/>

If your uploading the CSS with the solutions you can still tell SP where you want the CSS to go but this depends on what model you are using to develop the webpart.

Hope this helps.


  • +1 On using sharepoint css regisrations.... – BlueBird Mar 19 '13 at 14:06
  • Thanks alot Stephen. I solved this problem. Instead of adding to the masterpage i added everything in the SiteAssets on my site and used an url to link to it :) Cheers! – Annap Mar 19 '13 at 14:38
  • Nice one...has this been marked up as the answer? – Stephen Mar 19 '13 at 15:26

It is not possible to link to a CSS file with its server relative path as you have done.


When a user enters the site the site believes what it is programmed to believe which in this case is that the user has the CSS file on its C drive which it does not.

Stephen's answer is correct. I just wanted to point out the detail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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