When you access a list using web.Lists["Title"], you depend on list title being unchanged. What are the best practices for preventing such failures?
|
Just to add a SharePoint 2010 slant here - this issue becomes even more important if you have code which uses Linq, since there you have generated classes against the current schema of the list, and failures will occur if this schema changes and the classes are not in sync. My recommendation here is:
I prefer the first option though. Suggest that's a good way to treat lists which have code written against them, they are effectively 'system/application lists'. |
||||
|
|
|
Option 1. Use list GUID for indexing. This method may fail if the list is recreated from a template. |
|||||
|
|
There is no perfect solution, user should have contribute rights only. User who rename lists is an admin. Option 1: if you save the site as a template (stp) and create from that template a new one, you will get a new guid for the list. Option 2: changing url is possible using SPD and
|
||||
|
|
Option 2. Use the List's Web Relative Url which doesn't change and the web.GetViewFromUrl(url) method. Example:
This will break if the default (AllItems.aspx) view Url is no longer available for the list which is possible but less likely than the List title being changed. This method may also fail if someone changes the List URL using SharePoint Designer which is even less likely, but still possible. |
||||
|
|