1

I've been trying to use the method shown here:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistcollection.aspx

However, I'm getting this error on line 2 below:

Microsoft.SharePoint.SPWebCollection: type used in a using statement must be implicitly convertible to 'System.IDisposable'

SPSite oSiteCollection = SPContext.Current.Site;
using(SPWebCollection collWebs = oSiteCollection.AllWebs)
{
    foreach (SPWeb oWebsite in collWebs)
    {
        SPListCollection collSiteLists = oWebsite.Lists;
        foreach (SPList oList in collSiteLists)
        {
            Label1.Text += SPEncode.HtmlEncode(oWebsite.Name) + " :: " +
                SPEncode.HtmlEncode(oList.Title) + "<BR>";
        }
        oWebsite.Dispose();
    }
}

It won't allow SPWebCollection to be used in a using statement, because it doesn't inherit IDisposable.

Did MSDN make an error, or am I missing something?

1 Answer 1

2

You can surely expect errors in MSDN documentation. Right below the page, there is a Community Content area in which you can suggest them to correct the error or warn the readers of the MSDN content.

It can be corrected like:

SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebs = oSiteCollection.AllWebs

    foreach (SPWeb oWebsite in collWebs)
    {
        using(oWebsite)
        {
            SPListCollection collSiteLists = oWebsite.Lists;
            foreach (SPList oList in collSiteLists)
            {
                Label1.Text += SPEncode.HtmlEncode(oWebsite.Name) + " :: " +
                    SPEncode.HtmlEncode(oList.Title) + "<BR>";
            }
        }
    }
0

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.