Search code examples
sharepointwindows-sharepoint-serviceswss-3.0

How to get main site url inside webpart?


I need to get main site url from inside my custom webpart. Is there any programming way to do it?


Solution

  • Try :

            SPWeb currentWeb = SPContext.Current.Web;
            SPWeb rootWeb = currentWeb.Site.RootWeb;