a-list-doesn
Extending SharePoint: Checking if a List exists
July 6, 2009 by Staff · Leave a Comment
A common problem when working with the SharePoint Object Model is getting a handle to a list. Very often we find ourselves writing this: 1: try 2: { 3: using (var web = site.OpenWeb()) 4: { 5: if (web != null ) 6: { 7: try 8: { 9: var list = web.Lists[ListTitle]; 10: } 11: catch (ArgumentException) 12: { 13: web.Lists.Add(ListTitle, ListDescription, SPListTemplateType.GenericList); 14: } 15: } 16: else 17: { 18: Console.WriteLine( “Unable to open web site.” ); 19: } 20: } 21: } 22: catch (Exception ex) 23: { 24: Console.WriteLine(ex.Message); 25: } This adds a list if it doesn't exist on the site
Go here to read the rest:
Extending SharePoint: Checking if a List exists
