Question

What is the best way to get the url name of the list using CSOM.

For example, we have a list /sites/site/Lists/MyList/

We need "MyList".

We could get this, for example by parsing List.RootFolder.ServerRelativeUrl but is there a better way?

Was it helpful?

Solution

Try:

List.RootFolder.Name

It should work for both lists and document libraries.

OTHER TIPS

Example: how to get List Name by its Title:

public static string ResolveListUrl(string url, ICredentials credentials, string listTitle)
{
    using (var clientContext = new ClientContext(url))
    {
        clientContext.Credentials = credentials;

        var list = clientContext.Web.Lists.GetByTitle(listTitle);
        clientContext.Load(list.RootFolder);
        clientContext.ExecuteQuery();
        return list.RootFolder.Name;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top