SharePoint 2013 Using relative path in SharePoint master page


There is a few things that you can do if you want to use relative path for referencing an image or file.

1. You can place your images physically in the 15 hive folder under
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\IMAGES (or Layouts location)
Place a image here (logo.png) and you can access this image in your masterpage like this

2. Use img tag and you need add runat="server" attribute in this tag.

<img src="<% $SPUrl:~SiteCollection/Style%Library/Images/logo.png%>" alt="My Image" runat="server"/>
3. Use this:

<a href='<SharePoint:EncodedLiteral runat="server" text="<%$SPUrl:~SiteCollection/%>" EncodeMethod="HtmlEncode"/>' class="logo">
 <img src='<SharePoint:EncodedLiteral runat="server" text="<%$SPUrl:~SiteCollection/Style Library/CustomStyle/Images/logo.png%>" EncodeMethod="HtmlEncode"/>' alt="" />

</a>

Comments

Popular posts from this blog

SharePoint 2013 App Details Page Error

SharePoint 2013 - Working with Display Template for Content Search Web Part

Add spell check dictionary in SharePoint 2010, SharePoint 2013, and Office 365