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, a distinguished professional, boasts an impressive track record as a Microsoft MVP, having achieved this prestigious recognition for the eighth consecutive year since 2015. With an extensive career spanning over 18 years, Adnan has honed his expertise in various domains, notably excelling in SharePoint, Microsoft 365, Microsoft Teams, the .Net Platform, and Microsoft BI. Presently, he holds the esteemed position of Senior Microsoft Consultant at Olive + Goose. Notably, Adnan served as the MCT Regional Lead for the Pakistan Chapter from 2012 to 2017, showcasing his leadership and commitment to fostering growth within the tech community. His journey in the realm of SharePoint spans 14 years, during which he has undertaken diverse projects involving both intranet and internet solutions for both private and government sectors. His impact has transcended geographical boundaries, leaving a mark on projects in the United States and the Gulf region, often collaborating with Fortune 500 companies. Beyond his roles, Adnan is a dedicated educator, sharing his insights and knowledge as a trainer. He also passionately advocates for technology, frequently engaging with the community through speaking engagements in various forums. His multifaceted contributions exemplify his dedication to the tech field and his role in driving its evolution.

Leave a Reply

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