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

sharepoint

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.

Thanks.

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 = "http://portal.dev.muhimbi.local/sites/PDFConverterTest/subsite2/Shared%20Documents";
using (SPSite site = new SPSite(completeUrl))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPList list = web.GetList(completeUrl);
        string listName = list.Title;
    }
}