No need to dispose in 2010 at SPWebInfo object

Who has not encountered during the development toolpart - create a dropdownlist with a list of all sites.

The 2007 version used with SPWeb object and it must to make a Dispose.
 
// 2007
using (SPSite site = new SPSite("http://mysite"))
{
    foreach (SPWeb web in site.AllWebs)
    {
        ddlWebs.Items.Add(new ListItem(web.Title,web.ID.ToString()));
        // ... Continuing operations ...
        web.Dispose();
    }
}

The 2010 version we use object SPWebInfo.
In SPWebInfo we do not we will dispose.

Here is an example (in this case a loop that sets the title and ID for dropdownlist )

// 2010
using (SPSite site = new SPSite("http://mysite"))
{
     foreach (SPWebInfo webInfo in site.AllWebs.WebsInfo)
     {
          ddlWebs.Items.Add(new ListItem(webInfo.Title, webInfo.Id.ToString()));
          // ... Continuing operations ...
     }
}

SPWebInfo object contains:
Properties: Configuration, CustomMasterUrl, Description, Id, Language, LastItemModifiedDate, MasterUrl, ServerRelativeUrl, Title, UIVersion, UIVersionConfigurationEnabled, WebTemplateId
Methods : Equals, Finalize, GetHashCode, GetType, MemberwiseClone, ToString


Yours,
Roi

Comments

Popular posts from this blog

A sharepoint list view of the current month

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters

Export SharePoint 2010 List to Excel with PowerShell