Question

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.

Was it helpful?

Solution

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");

OTHER TIPS

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" />
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top