In SharePoint, sometime user finds it difficult to refer URL for any file in client side scripting languages like jQuery/javascript, so in this post I am sharing how to refer different level of sites using tilde (~).

  • ~site: is used to refer to current site URL.
  • ~sitecollection: is used to refer the current site collection URL
  • ~layouts: is used to refer the /_layouts/15 folder also know as 15 hive.

Usage example

  • ~sitecollection/style library/file name.js
  • ~site/siteassets/filename.js
  • ~layouts/osssearchresults.aspx

We also call it as relative path, I have seen developers providing absolute (fixed) path instead of related path. This happen mostly when they are inside a sub site so make sure to use ~site for referring lists This is one of the very basic thing but sometime we do not have idea and find it difficult to get it. I have seen this question on couple of forums so decided to write a small post about it.

Adnan is six time Microsoft MVP (Since 2015) with over 16 years of extensive experience with major expertise on SharePoint, SharePoint based development, Microsoft 365, Microsoft Teams, .Net Platform and Microsoft BI. He is currently working Sr Microsoft Consultant at Olive + Goose. He is MCT Regional Lead for Pakistan Chapter since 2012. He is working on SharePoint for past 12 years and worked on different intranet/intranet solutions for private & govt. sector majorly in United states and Gulf region and have experience of working with multiple Fortune 500 companies. He is a trainer, technology evangelist and also speaks in community forums.

Leave a Reply

One reply on “SharePoint how to refer file URL in client side script”