Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How to get the current site url in sharepoint, I am using SPContext.Current.Site.Url but this returns package 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 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

1 Answer 1

up vote 5 down vote accepted

It should be SPContext.Current.Web.Url

share|improve this answer

Your Answer

 
discard

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.