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#:
  1. public SPList ReturnListByUrl(string strPath)
  2. {
  3. if (strPath.ToLower().StartsWith("http"))
  4. {
  5. strPath = strPath.Substring(m_oWeb.Url.Length + 1);
  6. if (strPath.ToLower().StartsWith("lists"))
  7. {
  8. strPath = strPath.Substring(6);
  9. }
  10. }
  11. if (strPath.IndexOf("/")> 0)
  12. {
  13. strPath = strPath.Substring(0, strPath.IndexOf("/"));
  14. }
  15. return m_oWeb.Lists[HttpUtility.UrlDecode(strPath)];
  16. }

5 Responses to “Get SPList By URL In C#”

  1. Blogger Loser » Blog Archive » Get SPList By URL In C# Says:

    [...] 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) [...]

  2. 11 Links Today (2007-09-19) Says:

    [...] Get SPList By URL In C# [...]

  3. Blogger Loser » Get SPList By URL In C# Says:

    [...] 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 [...]

  4. aleksey Says:

    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.

  5. Craig Says:

    Some examples of usage would be useful.

Leave a Reply