1

See below:

SPWeb currentWeb = SPContext.Current.Web;
foreach (var web in currentWeb.Webs)
{
    // web is object here - why?
}

SPWebCollection implements IEnumerable<SPWeb> (among other things), so why doesn't it work?

The project framework is .NET 3.5, and I have other .NET 3.5 stuff in the same code.

Or is this just me? Can anyone reproduce?

3
  • 1
    Are you building it in .NET 2 or greater? Commented Feb 17, 2011 at 17:37
  • Make sure in this model you dispose of things properly too. (use the try-finally method). Read this for more info: sharepointnutsandbolts.com/2008/06/…
    – James Love
    Commented Feb 17, 2011 at 18:24
  • @Sébastien Yes, project framework is .NET 3.5. I have other .NET 3.5 stuff in my code.
    – ScarePoint
    Commented Feb 17, 2011 at 19:19

1 Answer 1

3

You haven't specified what your actual problem is, unless you are wondering why the variable "web" is an object. The reason it is an object is because you defined it as a "var", not an SPWeb. If you built your foreach loop like this:

SPWeb currentWeb = SPContext.Current.Web;
foreach (SPWeb web in currentWeb.Webs)
{
// web is now an SPWeb object.
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.