SPWeb.Configuration, bug?

I ran across this the other day while debugging something and thought I would share.

At first, I thought it was a problem in the site building tool I wrote and was using, but later confirmed this to be a problem even in a subweb created from the SharePoint UI.

What I saw

My test sites were generated from my SPSiteBuilder tool that uses SPWebCollection.Add(“site-relative URL”)

V2 Reference

http://msdn2.microsoft.com/en-us/library/ms980143.aspx

V3 Reference

http://msdn2.microsoft.com/en-us/library/ms411806.aspx

When you use this overloaded version of the Add method, in V2, it sets the sites template to the default STS#0 (Default Team Site), and thus SPWeb.Configuration results in 0.  In V3, it still works the same because you can immediately browse the site and it’s just fine, yet SPWeb.Configuration results in -1.

For example, given the following sample code:


public
static
void InspectWeb(SPWeb web, bool bRecurse)

{


Console.WriteLine(“web.Url: “ + web.Url);


Console.WriteLine(“web.ID: “ + web.ID);


Console.WriteLine(“web.Configuration: “ + web.Configuration);


if (bRecurse)

{


foreach (SPWeb subweb in web.Webs)

{

InspectWeb(subweb, bRecurse);

}

}

}

And the web was opened with by passing the URL to the SPSite Constructor, then calling SPSite.OpenWeb()

If I open the parent web first, and recurse I get the following:

C:\dev\sometool http://krichiewss3/sites/SPSiteBuilderSite1

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1

web.ID: 58faab9c-9bb6-46c6-9f99-46a08b5555b0

web.Configuration: 0

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1/SPSiteBuilderSite1_d1_w1

web.ID: 866311ca-c2a0-4d45-941f-ff1551b2954b

web.Configuration: -1

 

Yet, if I use the same code directly at that web:

C:\dev\sometool http://krichiewss3/sites/SPSiteBuilderSite1/SPSiteBuilderSite1_d1_w1

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1/SPSiteBuilderSite1_d1_w1

web.ID: 866311ca-c2a0-4d45-941f-ff1551b2954b

web.Configuration: 0

 

What I found

At first, I thought it was a bug in the SPWebCollection.Add() method. But I just confirmed that you get back the same result when you create a subweb via the UI as well. See below:

 

C:\dev\sometool http://krichiewss3/sites/SPSiteBuilderSite1

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1

web.ID: 58faab9c-9bb6-46c6-9f99-46a08b5555b0

web.Configuration: 0

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1/SPSiteBuilderSite1_d1_w1

web.ID: 866311ca-c2a0-4d45-941f-ff1551b2954b

web.Configuration: -1

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1/UICreatedWeb

web.ID: 130d7487-aa29-4774-b7db-c0a1e048edef

web.Configuration: -1

 

In the following test, I created the Site Collection and the subweb both in the SharePoint UI without custom code, yet enumerating the sub webs via SPWeb.Webs still produces the same result

C:\dev\sometool http://krichiewss3/sites/UICreatedSite

web.Url: http://krichiewss3/sites/UICreatedSite

web.ID: 907eacbe-f673-4c9a-be28-6c3f29bbf9ee

web.Configuration: 0

web.Url: http://krichiewss3/sites/UICreatedSite/UICreatedWeb

web.ID: 97798d22-c3b3-45ea-9bd8-a6b6e9150312

web.Configuration: -1

And if I just open that web directly:

C:\dev\sometool http://krichiewss3/sites/UICreatedSite/UICreatedWeb

web.Url: http://krichiewss3/sites/UICreatedSite/UICreatedWeb

web.ID: 97798d22-c3b3-45ea-9bd8-a6b6e9150312

web.Configuration: 0

 

I see no references to this property being neither deprecated nor obsolete. And I’ll need to let the powers that be know about it, just wanted to share with you that this appears to be a problem in WSS/MOSS RTM bits.

Then again, I could be missing something here, but you get two different results for SPWeb.Configuration depending on how you get a reference to the web.

  • Keith Richie

4 Replies to “SPWeb.Configuration, bug?”

  1. A small discovery on my part: Try using GetSubwebsForCurrentUser instead of Webs. SPWebs returned from that method have a correct return value for Configuration. Maybe this is a bug, but then maybe it’s something MS has done for performance reasons (i remember the Exchange 2k3 OM had similar gotchas.) Anyway, good luck and thanks for sharing!

  2. Actually in the implementation that I have to use, I can’t.
    There is a specific reason I have to do it this way vs GetSubWebsForCurrentUser.
    GetSubWebsForCurrentUser doesn’t return the web in heirarchial format, which is extremely important for what I’m doing.
    I could however get the Url from the Web and re-align the webs based on heirarchy internally.

    Thanks for the advice however!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: