Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Site/Subsite reference

  Asked By: Andrea    Date: May 22    Category: Sharepoint    Views: 1067

I am trying to get the guid for a subsite I've created. But... All I seem to get
back is the guid for the parent(top level) site. My code is:

SPSite sps = SPControl.GetContextSite(Context);
output.Write(sps.ID.ToString());

I've tried this as well:

SPSite sps = new SPSite(this.Page.Request.Url);
output.Write(sps.ID.ToString());

But I'm getting back the same guid/id whether I'm on the
http://<server>/sites/TestSite/default/aspx or on
http://<server>/sites/TestSite/SubSite1/default.aspx.

Do I have to iterate though the SPSitesCollections until I get the SPSite I
want, or is it possible to get it directly?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Lindy England     Answered On: May 22

SPSite refers to the site  collection, you want SPWeb instead which points at the
site.

SPWeb theWeb = SPControl.GetContextWeb(Context);
output.Write(theWeb.ID.ToString());

 
Didn't find what you were looking for? Find more on Site/Subsite reference Or get search suggestion and latest updates.




Tagged: