0
votes

I have a problem with SharePoint custom web part. It was successfully deployed and activated, and works on many tested environments, except one specific, so problem should be somewhere in SharePoint environment and not in Web-part itself.

When Web-part was added to any SharePoint page on that environment using default SharePoint UI, it can be added, but all images are not visible and other resources as well. They are however successfully installed and exist in FEATURES folder in SharePoint file repository.

I guess it is something with SharePoint configuration, permissions or something else, but have no idea what exactly could be?

1
Have you tried navigating to the URL of the resource you are trying to get to within your browser?Truezplaya

1 Answers

0
votes

The problem was in wrong URL of the resources. When used in root site:

http://mysite/

resources are loaded from the url

http://mysite/myresources/images/image1.jpg,

but when used on site that has URL like this

http://mysite/sites/site2

resources are still loading from URL

http://mysite/myresources/images/image1.jpg

but it was expected to be loaded from:

http://mysite/sites/site2/myresources/images/image1.jpg,

SOLUTION

Solution for this is adding GlobalPath to the resource path, so instead of using:

<img src="/myresources/images/image1.jpg" />

we should use this:

<img src=GlobalPath+"/myresources/images/image1.jpg" />

where GlobalPath is calculated this way:

var GlobalPath = _spPageContextInfo.siteServerRelativeUrl;
if (GlobalPath == "/") {
    GlobalPath = "";
}

Hope this could help somebody.