Get SPList By URL In C#

There was a question posted in the development newsgroups about how to structure a different SPList return method then the orthodox SPWeb.GetList method out of the Microsoft.SharePoint namespace. Here is one that I use, which has some slight enhancements.

[csharp]

public SPList ReturnListByUrl(string strPath)
{
if (strPath.ToLower().StartsWith(“http”))
{
strPath = strPath.Substring(m_oWeb.Url.Length + 1);
if (strPath.ToLower().StartsWith(“lists”))
{
strPath = strPath.Substring(6);
}
}
if (strPath.IndexOf(“/”) > 0)
{
strPath = strPath.Substring(0, strPath.IndexOf(“/”));
}
return m_oWeb.Lists[HttpUtility.UrlDecode(strPath)];
}

[/csharp]

Share