Skip to content

Using Relative Paths in SharePoint 2013 – MasterPages/Page Layout !!!

Hi all, you might have come across the scenario to make use of relative URL’s while creating Master Pages or Page Layouts in SharePoint 2013. As you all know we cannot have hard-coded paths/URL’s in our Page Layout. Following are the some of the ways I have used to make the paths relative and it works for sure in Page Layouts for SharePoint 2013.


Using in <a href>

The best way according to my knowledge is to make use of <asp:Literal> control…..

In this example, I have created the link which will point me to the Home Page of the Site Collection and the way to do is..

<a href='<asp:Literal runat=”server” Text=”<%$SPUrl:~sitecollection/%>“></asp:Literal>’>Home</a>

as you can see above I have made use of <asp:Literal> control and I have given the URL/Path  as <%SPUrl:~sitecollection/%>, so this will always point my Home link to home page of the site collection, where ever this Page Layout is deployed. 🙂


Using to include custom scripts

In order to add our custom scripts to our custom Page Layout, the way I tried to add them is using the following…

let’s say for example, if you want to add the skScript.js or can be any of your custom js which is in my Site Assets Library, the usual way we do is.


Now, “../../” depends where my current page is which is referring to this script, ideally this is not a good way to implement and there are chances it may break, if I move my custom page layout inside another folder in Master Pages and Page Layouts.

Now, same thing can be achieved by using <asp:Literal> control as show below in order to make it relative

javascript’ src='” />

SPUrl:~sitecollection/siteassets/js/skScript.js %>” />

<asp:literal runat=”server” Text=”‘&gt;&lt;/script&gt;” />

So, as you can see, by including our scripts using relative paths, we can be 100% sure, that this will never break even if we move the page layouts to any folder.


Using in Stylesheet

We can obviously have our custom style sheet for our page layouts depending on the requirements… so if we do it using drag drop or using Pick URL in SPD, we would end-up with something like this (assuming my css is in SiteAssests/Css)

siteassests/css/skCustomStyle.css” rel=”stylesheet” type=”text/css” />

Now, to make it relative, again <asp:Literal> control is to our rescue :).

We can do it in following way…



So the main crux of this article is, when-ever we want to make use of relative paths in Page Layouts or Master Pages (I have not yet used in Master Pages but should work),  we can make use of <asp:Literal> control….

Hope this helps to someone……!!!

Please leave comments if there is better way to achieve this…

Happy Coding !!!!



VS 2012- No exports were found that match the constraint…….

No exports were found that match the constraint
Today I came across this error where I was not able to create new project….

To me this seems to be VS Cache issue, in order to resolve this, I deleted (or you may rename) the folder (ComponentModelCache) which can be found at following location.


Hope this helps…

happy coding…. Smile

SharePoint 2013 Enable Detailed Error

Hi, we as developers always wanted to see the details errors at least in the development stage, as we want to see the error right on the screen instead of going to SharePoint Logs.

We as a developers always prefer to see the errors on the screen. Like we did it for WSS 3.0, MOSS 2007, SharePoint 2010, we can enable detailed errors for SharePoint 2013 as well.

Following are the steps to follow.

Step 1) Step the following in the web.config of the web application in concern

1)      <customErrors mode="Off" />

2)      <compilation batch="false" debug="true">

3)      <SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10" TotalFileDependencies="250" AllowPageLevelTrace="false">

Step 2) Along with this it is very very important to set customErrors mode="Off" in _layouts

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\web.config

Hope this helps some developer looking for detailed error in SharePoint 2013.

Configurable Silverlight XAP file

Hi, I came across the situation, where in my Silverlight application needs to be deployed in different client environment where I have to change the service reference every time in my XAP file, before knowing I use to change the service reference and rebuild the application and generate the XAP file. So every time I used to change the service reference and rebuild the application which generates new XAP file.

Solution to above problem, we can have this XAP file configurable without rebuilding the application again, so that you can walk to any client’s environment just do the following and your new XAP with new service reference is ready for you.


Steps to be followed

1. Rename the *.XAP file to *.ZIP (since XAP is compressed file)

2. Extract this renamed ZIP file and you will find all the *.dll’s along with your application dll plus you will see ServiceReference.ClientConfig file.

3. Change the service endpoint as per your needs in this client config file and pack all these extracted files back to ZIP file.

4. Rename this ZIP file to XAP and you are done.

You have now new XAP file that is referencing to new service endpoints without rebuilding the application.


Hope this helps. !!! Smile

(Note: Tested and Verified with Silverlight 4)

Disable F5

The following JavaScript will disable the F5 key stroke in the browser.


<Script language="javascript" type="text/javascript" >

function checkKeyCode(evt)


var evt = (evt) ? evt : ((event) ? event : null);

var node = ( ? : ((evt.srcElement) ? evt.srcElement : null);



evt.keyCode=0;return false;





JavaScript: Method to get elements by Class

There are various get methods available in JavaScript, but something I was looking for was to get the element by class name, which was very much required in one of my assignment.

I searched over the internet and found few ways to do it. Following is the one the method that I used. Hope it helps someone in search of it.


function getElementsByClass(searchClassName,node,tag

  var classElements = new Array();
  if (node == null)
    node = document;
  if (tag == null)
    tag = ‘*’;
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClassName+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if (pattern.test(els[i].className) ) {
      classElements[j] = els[i];
  return classElements;

SharePoint: Hiding Quick Launch Bar

Sometimes we need to hide the quick launch bar in SharePoint 2010, one of the easiest way to do this is the following style tag.





Note: Put the above code in a txt file and place the file in the style library, add the CEWP on the page and give the link to the txt file.