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!
greddinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
Did you try web.Url?
0
greddinAuthor Commented:
I thought web.Url would return the entire url.  Is this not the case?
0
Kyle AbrahamsSenior .Net DeveloperCommented:
Sorry, I misread the question . . . in that case you can do a substring on it:

web.Url.ToString().Substring(web.Url.ToString().LastIndexOf("/")+1);

Open in new window

0
greddinAuthor Commented:
I think I solved my own question.  It seems I didn't need the SPSite in my content.

This works:

SPWeb = web = SPContent.Current.Web;
Response.Write(web.Name);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
greddinAuthor Commented:
I solved this myself eventually, but I'm also accepting Kyle's solution as an alternative approach.  Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.