Get SPList By URL In C#
Posted in SharePoint 2007 Development |Posted by Adam Buenz
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.
C#:
-
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)];
-
}











September 19th, 2007 at 6:42 am
[...] 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 Read More……(read more) [...]
September 19th, 2007 at 8:23 am
[...] Get SPList By URL In C# [...]
September 21st, 2007 at 11:24 am
[...] 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 Read More……(read more) September 21st 2007 Posted to Uncategorized [...]
October 9th, 2007 at 9:10 am
Method, described in the article will not work for international lists because there list names and relative paths are not the same:
example: My библиотека
but relative path will be the following:
/lists/my/
so the best solution is to use SPWeb.GetList method. But be careful - you must use ABSOLUTE path rather than relative as described in MSDN - it's mistake.
May 22nd, 2008 at 5:00 am
Some examples of usage would be useful.