Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

5 Answers 5

up vote 21 down vote accepted

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.

share|improve this answer
    
Shared some details of performance hit in my answer. –  dbardakov Aug 22 at 13:32

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.

share|improve this answer

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...

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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