SharePoint site and relative url issue
-
21-12-2020 - |
Pregunta
I have set one image as a background image in SharePoint Master page.
So here issue I am facing is in displaying this image in my non-root site collection.This works perfectly in my root site collection.
I am using a relative path to the library to display image ex. /Images/coffeebean.jpg
.
By using developer tools I came to know that hovering on that relative path image it shows the path from the root site collection.
http://SITECOLLECTION/Images/coffeebean.jpg
instead of
http://SITECOLLECTION/sites/test/Images/coffeebean.jpg
I don't want to use absolute URL.
Any help will be appreciated!!
Solución
There are 2 ways you can insert an image in a SharePoint master page. Both of them are relative url.
14 Hive (Physically hosted): You can place your images physically in the 14 hive folder under C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES
Place a image here (logo.png) and you can access this image in your masterpage like this
<SharePoint:SiteLogoImage LogoImageUrl="/_layouts/images/logo.png" runat="server"/>
Site Collection (Library hosted) Upload the logo.png file in any document library on your site collection. If your library name is "Images" here is how you can access the image.
<img src="../../Images/logo.png" />
Both the approaches are fine depending on your portability requirement of the site.
Check the below MSDN links for reference
Understanding Absolute and Relative URL Addresses
MSDN Forum link Adding relative image in master page