5

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?

2 Answers 2

6

Try:

List.RootFolder.Name

It should work for both lists and document libraries.

2

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 and acknowledge you have read our privacy policy.

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