7

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?

migrated from stackoverflow.com 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
13

It should be SPContext.Current.Web.Url

-3

Try this

string urlpath = "http://" + HttpContext.Current.Request.Url.Authority + "/Sites/" + siteCollectionName;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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