4

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?

5

Try:

List.RootFolder.Name

It should work for both lists and document libraries.

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.