What would be the complete code for a best practice to get a list using CSOM?

A couple of related questions:

  • Should we always return all the lists first, and then run a linq query to select the correct one?
  • What property should we use to get the list? I would like to use the url name ( /MyList/ ) instead of Title or Guid because Title (at least theoretically) should be changable and Guid gets difficult between environments (dev/test/qa/on-premises/O365). Is there a property for this url name (without web url)
  • Would the approach be the fastest in most scenarios?

I would also like to have some reasoning behind the proposed solution.

  • voted up, i also seek for the best practice so far.. Commented Jan 2, 2014 at 7:59

1 Answer 1


As always it depends.

  • Getting the list by title will give you the best performance as the ListCollection.GetByTitle doesn't even require a trip to the server before you can use the list. But it has the downside that the user can easily change the title and make your code fail.

  • Getting the list by Url or Id will require you to retrieve these properties for all list which require a round trip to the server. Using the Url (relative) will work across sites, but the user has the possibility of moving the list which will then again break your code.

In cases where I can't trust the users not to change things they should leave alone and on the other hand I need to be able to have the code working as stable as possible across sites I've used the approach of:

  • storing Id and Url in a web.property (assume Guid.Empty and default url if nothing is stored)
  • retrieve Id and Url of all lists
  • if any Id match use that list (and update the property if the Url isn't right)
  • if no Id match by an Url does use that list and update Id
  • if no Id nor Url match then cry

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.