开发者

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

开发者 https://www.devze.com 2022-12-15 06:06 出处:网络
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 fi

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 libra开发者_开发百科ry as input and provides the document library name.

Appreciate any thoughts.

Thanks.


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;
    }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消