Get list by url

03/02/2016 02:07

//e. g. listUrl is '/Lists/Announcements' or library '/Shared Documents'
public static SPList GetListByUrl(SPWeb web, string listUrl)
{
 string listRelativeUrl = SPUrlUtility.CombineUrl(web.ServerRelativeUrl, listUrl);
 try
 {
  SPList list = web.GetList(listRelativeUrl);
  return list;
 }
 catch (FileNotFoundException)
 {
  return null;
 }
}