3

I am working on a web part for Sharepoint 2010. I have several CSS and JS references that are declared at the top of the .ascx file. I deployed my web part and ran it in Sharepoint to find that certain styles were missing. Opening the network tab of dev Tools in Chrome showed that several CSS and JS files could not be found (HTTP 404 error).

This is actually wrong, it should say sites/kohlerdmr/sitepages/~/layouts/.... read on below

So initially I just didn't deploy my resource files to the server. A co-worker told me to setup a "Sharepoint Layouts Mapped Folder" which I did. Added it to my project, then put the .ascx and the css/js folders in that Layouts folder. So I deploy again. This time the files are actually in the Sharepoint drive (Common Files\Microsoft Shared\Web Extensions\14\TEMPLATES\LAYOUTS\My Project (or something similar to that). Great...

Well I am very confused about how I am supposed to reference these files. It doesn't seem like I can browse to them. I really have no idea what the URL of the layouts folder is. I've tried http://server/sitecollection/_layouts/layouts/[project name]/css/file.css and some variations. Currently my references are deployed in this format:

<link href="<%=Server.ResolveClientUrl("~/Layouts/DMR Entry Webpart/css/jquery-ui.css")%> rel="stylesheet" type="text/css" />

I've also tried /Layouts, ~/Layouts, /css, and those all threw warnings saying the directory/file does not exist.

Current look at my solution structure:

enter image description here

Hopefully someone can help, thanks.

NOTE: The 404 NOT FOUND errors in the first screenshot were caused by my web part being referenced in multiple places. By completely retracting and removing the web part, creating a new web part in the VS solution and copying the code over, the new web part works correctly.

Thanks

3 Answers 3

0

They will be located at a path like http://yoursp.yourdomain.com/sites/site/_layouts/DRM Entry Webpart/css/bootstrap.css in your above image.

1
  • That seems to be the correct URL. It helps, but I am still getting the exact same 400 errors. I've updated my question.
    – Paul
    Oct 7, 2014 at 13:52
0

Use this URL

/_layouts/<projectname>/folders if any until you find your css files/<cssfile>.css

0
0

Try generating relative URL for your resource files.

<link rel="stylesheet"  type="text/css" href='<asp:Literal runat="server" Text="<% $SPUrl:~Site/%>" />SiteAssets/abc111.css'  />

Or

<SharePoint:CssRegistration Name="<% $SPUrl:~Site/SiteAssets/File.css %>" runat="server"></SharePoint:CssRegistration>

Or

<Sharepoint:CssLink runat="server" DefaultUrl="<% $SPUrl:~Site/SiteAssets/File.css %>"/>

Check out following link to generate relative path: http://customsp.blogspot.com/2014/10/relative-path-in-sharepoint.html

1
  • We do not allow link only answers with the sole purpose to promote your private blog. Please add details to your answer here, and at most use the link to your blog as a reference only Oct 21, 2014 at 5:59

Your Answer

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

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