10

I know its always best to access a list by its Guid since it won't ever change, compared to accessing a list by Title or Url, but what are the other benefits of grabbing a list by the Guid?

There are times when I know the default URL or list Title, but have no idea what the Guid is until I look it up using the Url or Title. Once I have the guid, is it always best to continue accessing the list via the Guid?

5 Answers 5

23

The main advantage is a small performance benefit. Internally SharePoint is always using the GUID so the other methods have to find the GUID and the do the lookup using the GUID.

The second advantage is that the user can't change the GUID.

1
  • Shared some details of performance hit in my answer.
    – dbardakov
    Commented Aug 22, 2014 at 13:32
3

To elaborate on the second advantage above, short of an item being deleted, you are guaranteed to receive the same object for the duration of your process.

This makes it possible to do things like change any and all options with your list, and still be able to properly reference it, or more practically, you could update page links that go to a certain item, and change an item name in any order (or at the same time with asynchronous functions).

Furthermore, if the code your using is dynamic, you only need a single try or if statement to ensure the item is successfully retrieved, rather than one every time you attempt to grab it.

2

I know I'm stating the obvious, but you'll want to use the title rather than the GUID if you are building a site template.

So, no, the GUID is not always the best choice...

0

One of the practical examples why to use IDs (though of sharepoint list items) instead of e.g. Title as Value: Drop-Down List Box (in its properties) when used in Infopath repeatable section/table and its datasource being a sharepoint list field. While the non-ID column name also would work as value, but in this case one should update default values of mentioned control when the sharepoint list content used as datasource are changed (edited/changed/updated, added) by user. See, for example, how to display dropdowns with it's values selected automatically in the Repeating Table

0

I compared 2 separate list requests:

  1. web.GetList("Lists/MyList")
  2. web.List[myListGuid]

Using SQL Server Profiler, I captured extra procedure call (proc_GetTpWebMetaDataAndListMetaData) to get the actual listGuid.

Keep in mind all the overhead to create, process, log that extra request. Is it a small performance hit or not in your case - up to you) SharePoint (as of 2007/2010) can't be called extremely fast anyway.

I personally prefer to use Guid's once I get it.

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.