Getting A List By View URL

It is relatively straightforward to retrieve a list name, or even a strongly typed SPList object in a static reusable format. This can be done with the following:

public string GetListNameFromViewUrl(string currentViewUrl)
int index = currentViewUrl.IndexOf(“?”, StringComparison.Ordinal);
if (index != -1)
currentViewUrl = currentViewUrl.Substring(0, index);
ParentSite.Lists.ListsForCurrentUser = true;
SPList list = null;
foreach (SPList spList in from SPList spList in ParentSite.Lists
where (spList.Views != null) && (spList.Views.Count != 0)
where (from SPView spView in spList.Views
select new StringBuilder(ParentSite.Url).Append(“/”).Append(spView.Url)).
Any(builder => currentViewUrl.Equals(builder.ToString())) select spList)
list = spList;
if (list == null)
throw new Exception(“Not View In Page”);
return list.Title;