0
votes

Today I came across and an issue setting the Preview Image for the Custom Site Template in SharePoint 2010 using Sandbox solution.

I have used the Team site template and given the Icon image in ImageURL in Elements.xml file. As its sandbox I am storing the image file inside the site collection Styles Library. My question is how to give the relative URL for the image url which is present in Site Collection Styles Library.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<WebTemplate BaseConfigurationID="0" 
           BaseTemplateID="1"
           BaseTemplateName="STS"
           Subweb="FALSE"
           Name="WTTeamSite"
           Title="Team site"
           Description="Create a Team site"
           ImageUrl="/Style Library/img/site-icon.png"
           DisplayCategory="Custom" /> 
</Elements>

If I give full url eg: http://wsdl:3333/sites/Corporate/Styles Library/img/site-icon.png it works. But If I give relative URL like [../../Styles Library/img/site-icon.png] or [../Styles Library/img/site-icon.png] or [~sitecollection/Styles Library/img/site-icon.png] or [Styles Library/img/site-icon.png] or [/Styles Library/img/site-icon.png] doesn't work. How to make this preview image work using relative URL.

Note: I cant use layouts folder as it has to be sandbox solution. Thanks.

1

1 Answers

0
votes

I think the issue is because of how you are referencing the URL.

When you have a relative URL, the reference is relative from the webapp level. e.g. http://wsdl:3333/

So, using the URL that you have provided, if you want a relative URL, your ImageURL will be:

/sites/Corporate/Styles Library/img/site-icon.png

To verify that you have a "good" URL I like to run tests by changing the Site Logo and clicking on the "Click here to test" link.

This is where you encounter the disadvantage of sandboxed solutions, where the URL chanqes depending on the Site Collection, and the advantage of having a farm solution with access to the "/_layouts/Images" mapped folder, where the URL will not change.

A possible workaround that I have used would be to place the image on the root site, or have a static site collection called "Resources", or something, where you put things that you need to have global access to, and it's a known URL.