9

I want to know the fastest way to access a list. Would it be:

            SPWeb web = site.RootWeb;
            SPList activityListFromUrl = web.GetList("/Lists/ActivityList");

or:

            SPWeb web = site.RootWeb;
            SPList activityListFromGuid = web.Lists[new Guid("aaa-aaa-aaa-aaa")];

or perhaps some other way?

2
  • 1
    Duplicate of sharepoint.stackexchange.com/questions/32898/…
    – Andy Burns
    Commented Mar 29, 2012 at 17:13
  • 1
    Its not a duplicate, I posted both those questions and I believe they are asking different things. This is regarding speed, the other is regarding general benefits of using a Guid vs a Title or URL. Commented Mar 29, 2012 at 17:50

2 Answers 2

14

web.Lists[guid] is the fastest.

web.GetList(url) calls a couple of methods to get the guid and then returns web.Lists[guid]

1
  • web.Lists[guid] - is not fastest. For some reason, TryGetList is faster!
    – Aviw
    Commented Apr 29, 2014 at 5:30
0

The only way to definitively answer "faster" type questions is to test in your environment.

Your farm (hardware, network, etc.) is going to be different than everybody else. So any advice you get will not apply to your configuration.

2
  • Does web.Lists[guid] load all the site lists into memory before accessing it like web.Lists.TryGetList() does? Commented Mar 29, 2012 at 16:11
  • No matter the answer to the question, performance can only be measured by doing actual measurements. (And the answer could be determined by reflecting those methods.) Commented Mar 29, 2012 at 19:43

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.