Retrieve the name of SharePoint Document Library name using Document Library URL


We have a requirement to retrieve document library name based on the URL of a document library. We have searched through all the methods offered by "List" web service in SharePoint, but could not find any method that takes the URL of the document library as input and provides the document library name.

Appreciate any thoughts.


Best Solution

I don't think you can easily do it in a single line of code, but the following works with both URLs pointing directly to the document library as well as pointing to a file in that library

string completeUrl = "";
using (SPSite site = new SPSite(completeUrl))
    using (SPWeb web = site.OpenWeb())
        SPList list = web.GetList(completeUrl);
        string listName = list.Title;