Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

SharePoint developers?

Back to Forum: Tech Off
  • User profile image

    If there are any SharePoint developers here, starting out with some custom SharePoint WebParts development here and need some help.  It seems in a lot of samples in the docs and on the web, people use the Webs property of the SPWeb class to retrieve sub sites but I get an exception:

    "This property is not available. To retrieve this property, you must first obtain a SPWebCollection from the GetSubwebsForCurrentUser method. You then need to initialize the SPWebCollection by accessing it with the integer indexer."

    While I was able to do this at a basic level... it seems almost silly when the same exception occurs in the following code:

    foreach (SPSite subSite in siteCollection)
        SPWeb subWeb = subSite.RootWeb;
        // Exception when attempt to access
        // subWeb.Name, or other property...

    Am I really supposed to call that method and use an indexer before being able to access SPWeb's properties every time (especially silly in something as above)?  Or am I doing something wrong?  I hope I'm doing something wrong...

  • User profile image

    Hrm, nm... there is a lot of errors in the details in the above.  First, the inability to access the Webs property seems to be due to some security issues.  Second, the bit of code is fine but it turns out that .Name returns an empty string for top-level sites (which I was accessing).  The exception itself was due to accessing .Created (immediately after the .Name - should've caught that) which in the docs is described as being only available when SPWebs are created using GetSubwe...

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.