SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to get the current site url in SharePoint?

I am using SPContext.Current.Site.Url but this returns parent site url.

If I create a new site in existing site and activate my feature in it, and call it, it doesn't returns me current site url, it returns me the parent site url.

Any idea?

share|improve this question

migrated from Aug 5 '11 at 13:48

This question came from our site for professional and enthusiast programmers.

SharePoint has confusing mismatch between object names and what people call sites: SPSite is "site collection", SPWeb is "site". So you call actually returns Url to site collection that is one of the ancestors of your site (not necessary immediate one). – Alexei Levenkov Aug 3 '11 at 7:17
Object "Site/SPSite" refers to Site Collection. Object "Web/SPWeb" refers to the site. This is just because of poor naming conventions from the sharepoint team. Try SPContext.Current.Web.Url – vasya10 Aug 5 '11 at 15:30
up vote 7 down vote accepted

It should be SPContext.Current.Web.Url

share|improve this answer

Try this

string urlpath = "http://" + HttpContext.Current.Request.Url.Authority + "/Sites/" + siteCollectionName;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.