Translate

Sunday, August 19, 2012

Using TryGetList in sharepoint 2010

TryGetList in sharepoint 2010


How to get the list directly without looping through SPWeb List collection
There is a Provision in SharePoint 2010 "TryGetList" actually will give the list by passing the list name

Here is sample to demonstrate the "TryGetList"

            SPSite site = new SPSite(SPContext.Current.Web.Url);
            SPWeb currentWeb = site.RootWeb;

            SPList customList = currentWeb.Lists.TryGetList("MyCustomList");

No comments:

Post a Comment