Sharepoint lead is a place where you can read about interesting topics related to sharepoint, and you can also post comments and suggessions.

Monday, July 2, 2012

Sharepoint 2010: TryGetList vs GetList

As a developer, you will say GetList can throw exception but TryGetList will not. It is actually confusing because TryGetList looks for listTitle and returns null if list is not available at expected location. GetList will expect listUrl and can throw FileNotFoundException or ArgumentException if list is not present at expected location or relative/absolute url of list is invalid relatively. Another biggest difference is they belong to different class!

Apart from all those technical details, I noticed that many sharepoint administrators likes to start with a simple list/library name and eventually change it to make it as close as possible to what they do. That will make list/library url and their names different. Here comes the actual problem. If you are actually using list/library names in your code, it will no longer work. OR we can say you are not allowing sharepoint administrators to change name of list/library that they have created. 

By using GetList you are actually giving them flexibility to use whatever name they like to use, as far as they are not changing url or list/library code will still work.

In conclusion, it really depends on requirements how you are going to deal with the situation but it is good to keep in mind that you can use GetUrl function in your code to allow sharepoint administrators to change their names without worrying about breaking functionality.

No comments:

Post a Comment