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:

[csharp]
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;
}
[/csharp]

Share

One thought on “Getting A List By View URL”

  1. Hello, all is going sound here and ofcourse every one is sharing data, that’s really good, keep up writing.

Leave a Reply

Your email address will not be published. Required fields are marked *