Link to home
Start Free TrialLog in
Avatar of greddin
greddinFlag for United States of America

asked on

How to get just the site's name?

Consider the following url.  I'm wanting to just return the site's name/id.  The same thing that's in a Url.   In this case I want to return just - MyTeamSite
 
http://somedomain.com/team/MyTeamSite

I'm using the following code, but the web.Name is coming back empty.  

using (SPSite site = new SPSite(SPContent.CurrentSite.ID)) {
    using (SPWeb web = site.OpenWeb()) {
        Response.Write("name = " + web.Name);
    }
}

Open in new window


What am I missing or doing wrong?  Is there a better way of doing this?

Thanks!
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Did you try web.Url?
Avatar of greddin

ASKER

I thought web.Url would return the entire url.  Is this not the case?
SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of greddin

ASKER

I solved this myself eventually, but I'm also accepting Kyle's solution as an alternative approach.  Thanks!