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 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.
精彩评论