Search code examples
c#sharepointsharepoint-2010

Getting SPList by a value from SPListTemplateType Enumeration


I am working on an older project from 2009 and there is something like

SPList tasksList = web.Lists["Tasks"]

which was used to get the SPList. But because of language troubles we couldn't write "Tasks".

I would like to replace "Tasks" with 107 or even better the SPListTemplateType enumeration, such as

SPList tasksList = web.Lists[SPListTemplateType.Tasks];

Which does not work because Lists expects a GUID but it is unclear how to achieve that.


Solution

  • You can use the BaseTemplate property in a LINQ query:

    SPList tasksList = 
                     web.Lists
                        .Cast<SPList>()
                        .FirstOrDefault(list => list.BaseTemplate == SPListTemplateType.Tasks);