tags:

views:

245

answers:

2

Hi, 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.

+1  A: 

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;
    }
}
Muhimbi
+1  A: 

Just to add to that, if you are looking for getting the Document library name from the Url, then it's best to use the object model. Once the document library is created, the url of the document library is fixed and therefore changing the name will not reflect in the url.

Faiz
Thanks for your answer. I am looking to use out of the box web services provided by SharePoint due to some restrictions that I cannot deploy.NET code on SharePoint server.