0

I developed a SharePoint 2010 WebParts with JavaScript and CSS(inside a module). I haven't problem on development environment but in production environment.

In production environment I have a WebApplication (http://productionapplication/) with managed path "corp" (http://productionapplication/corp/) and a SiteCollection "product" (http://productionapplication/corp/product).

GET HTTP request fail for my JavaScript and CSS on loading my WebParts. Script and CSS are correctly deployed inside "http://productionapplication/corp/product/MyDocumentLibrary/"

How can I resolve my problem?

Thanks for your support.

  • How did you reference the static resources from within the webpart? – MdMazzotti Apr 23 '14 at 12:56
  • Hi, I add simply code like that inside WebPart: <link rel="stylesheet" type="text/css" media="screen" href="/MyDocumentLibrary/Css/example.css" /> – ilMattion Apr 23 '14 at 12:59
1

Because you're on SharePoint Foundation (thus you cannot use the $SPUrl expression), I would suggest that you resort to some classic ASP.Net tricks to workaround your issue:

Add a runat="server" and id attributes to the link element

<link id="css1" runat="server" rel="stylesheet" type="text/css" media="screen" href="" />

Within the Page_Load method, add this code:

css1.Attributes["href"] = SPUrlUtility.CombineUrl(SPContext.Current.Web.ServerRelativeUrl, "/MyDocumentLibrary/Css/example.css");
| improve this answer | |
  • Hi Mazzotti, I try your solutions as soon as possibile. Thanks – ilMattion Apr 28 '14 at 12:09
  • Hi Mazzotti, now my application work correctly. Thanks! – ilMattion Apr 29 '14 at 16:20
  • @ilMattion glad I helped – MdMazzotti Apr 29 '14 at 16:29
1

Try the SPUrl token:

<link rel="stylesheet" type="text/css" media="screen" href='<% $SPUrl:~site/MyDocumentLibrary/Css/example.css %>' />

If that doesn't work, try the full relative path to you managed path:

<link rel="stylesheet" type="text/css" media="screen" href="corp/product/MyDocumentLibrary/Css/example.css" />
| improve this answer | |
  • Hi, I added your code but I have this error: Literal expressions like '<% $SPUrl:~site/MyDocumentLibrary/Css/example.css %>' are not allowed. Use <asp:Literal runat="server" Text="<%$SPUrl:~site/MyDocumentLibrary/Css/example.css%>" /> instead. – ilMattion Apr 23 '14 at 13:26
  • @Marco try what the error message is suggesting. <link rel="stylesheet" type="text/css" media="screen" href='<asp:Literal runat="server" Text="<%$SPUrl:~site/MyDocumentLibrary/Css/example.css%>" />' /> – MdMazzotti Apr 23 '14 at 13:29
  • Thanks, now I have this error: The expression prefix 'SPUrl' was not recognized. Please correct the prefix or register the prefix in the <expressionBuilders> section of configuration. I'm looking for this problem. – ilMattion Apr 23 '14 at 13:32
  • @marco sorry, I noticed only now that you're on SP Foundation, where SPUrl is not supported – MdMazzotti Apr 23 '14 at 13:34
  • Sorry, I not specified that. Now I try second solution. – ilMattion Apr 23 '14 at 13:36

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.