I have created css file called stylesheet1.css in folder called Mystyles. See image below

I want to refer css file in my visual studio in one of my .aspx page, so i wrote something like this but its not using this stylesheet

<link href="~sitecollection/_catalogs/masterpage/MyStyles/Stylesheet1.css"  />

Please can someone tell how can i refer this? Also could be nice if there are any articles which i can read about to get idea about referring images and css files in sharepoint in different ways.

enter image description here

1 Answer 1


A correct way to reference a CSS from your master page is:

 <SharePoint:CssRegistration Name="&lt;% $SPUrl:~sitecollection/_catalogs/masterpage/MyStyles/Stylesheet1.css %&gt;" runat="server" After="corev15" />

Yup, surprising, but fully functionnal on my side! This is the only way to set a dynamic reference to a CSS...

  • This i have done as well. But when i do this and if i change something in my stylesheet for example i wanted to override some bootstrap classes but it doesnt take any effect.
    – Happy
    Apr 14, 2015 at 8:20
  • How do you edit the CSS? From the Library itself (with SPD or by uploading a new file) or from the WSP package that you redeploy with an Update-SPSolution? Is it a farm solution or an App? Did you use Ctrl+F5 to reload the page in the browser to ensure no client-cache is involved?
    – Evariste
    Apr 14, 2015 at 8:56
  • I just edit in my visual studio and then i deploy sharepoint solution. Ok so i can only edit that by uploading new file or edit in SPD?
    – Happy
    Apr 14, 2015 at 9:40
  • No, you should have both options: 1. Edit after deployment with SPD or uploading a new file (that would "unghost" the file, see that little blue icon in SPD after editing?). 2. Redeploy the package with the edited version (will only work if the file had never been unghosted previously). Can you ensure Type="GhostableInLibrary" is set in your elements file for each file you provision with the feature?
    – Evariste
    Apr 14, 2015 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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