0

Sorry if this could already have been answered but I am new to Sharepoint Online.

With previous versions of Sharepoint, this has been working fine for me until now.

  1. Upload an HTML, CSS and JS files within any document repository in Sharepoint
  2. Call the CSS and JS files using traditional src="/RelativePathToTheCSSandJSFiles"

With Sharepoint online, this seems to no longer work. For testing purposes, what I do now is this:

  1. Upload .ASPX file within the default Document folder of a site collection I created
  2. Upload the CSS and JS files within the default Style Library Folder

enter image description here

  1. Called the CSS file using the following script

enter image description here

  1. Called the JS file using the following script

enter image description here

Am I doing this the right way? Please help.

  • Is there a reason to upload .aspx pages in SharePoint that way? What are you trying to do? – Mohamed Derhalli May 29 at 13:11
  • Sharepoint Designer is not enabled. – Alex M May 30 at 4:45
  • OK, but what are you trying to do? Why are you creating custom aspx pages rather than using SharePoint pages themselves? Do you need to have custom code in there? – Mohamed Derhalli May 30 at 13:38
  • Yes. I will be adding custom JS and CSS together with the custom HTML – Alex M Jun 1 at 16:19
  • The way to do it is with SPFx, is there a reason to go for aspx pages rather than spfx web parts? – Mohamed Derhalli Jun 2 at 13:16
0

Consider using <SharePoint:CssRegistration> content placeholder, which defines the CSS file:

<SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/Style Library/CSSTest.css%>" runat="server"/>

And at runtime:

<link rel="stylesheet" href="/sites/KnowledgeManagement/Stype%20Library/CSSTest.css" type="text/css" media="all" />

References:

Use CSS to brand SharePoint pages.

SharePoint CSSRegistration or Link?

| improve this answer | |
  • Thanks Chelsea_MSFT. Sorry but I am new to this. Given the structure I have shown above, where do I input the <SharePoint:CssRegistration> code? Can I put that within the ASPX file I created within the Documents folder? – Alex M Jun 1 at 16:21
  • 1
    @AlexM If you just want to call the css file within one aspx file, the line you provide in the original post should work as expected. Another reference: sharepoint.stackexchange.com/questions/221030/… – Chelsea_MSFT Jun 2 at 6:35
  • Absolute URL to the CSS file worked! Thanks! – Alex M Jun 4 at 19:59

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.