I have many lists, some of which were created using a custom and now-obsolete list definition. I need a programmatic way of finding out which lists were created using that old definition.

Currently my workaround is to check the ServerTemplate attribute in the list's PropertiesXml:

SPList.PropertiesXml.Contains(string.Format("ServerTemplate=\"{0}\"", oldTemplateId))

Is there a method to do this without iterating through lists and comparing properties? Are there any other properties I can use to identify which list definition the list is based on?

  • Question is unclear on what exactly the problem is causing users to post answers that are unsatisfactory to you. Feb 29, 2012 at 17:17
  • 1
    @tylerrrr07: I've already attempted to clarify by adding the [object-model] tag (following the two PowerShell answers, despite the C# code sample), but I'm really at a loss as to what extra information I can add. I've already got some background, an example of what I'm doing, and a request for a any better methods to get the same (or similar) information. If you have any suggestions for additional clarification then they're more than welcome.
    – Stu Pegg
    Feb 29, 2012 at 17:43
  • The off-topic (PowerShell) answers have been re-upvoted after my downvotes; this means anyone looking at this in future may end up chasing wild geese, which is unfortunate.
    – Stu Pegg
    Feb 29, 2012 at 17:56
  • Honestly on a first pass I thought you were looking for a way to query the site for lists based on list definition but I think the focus is more on the properties because you already have an SPList? I'm not sure if you are looking for a different way to get "ServerTemplate" or just an alternate way to identify a List Definition via the API. The answers provided give you ways to access list properties but don't tell you what properties would be useful which is where I'm sure you think they fell short. Your question is actually very good. We are just doing too much guessing to effectively help. Feb 29, 2012 at 18:19
  • @tylerrrr07: I'm looking for any way to identify lists created using a certain definition, my only caveats being that the answer should a) Use the Object Model, b) Be more efficient than my current rather bodgy workaround. All of which I've tried to make clear in my question. :| As it stands, this question isn't of use to anyone with this problem at present or in future, so I'll leave until tomorrow and then delete it if there are no further answers.
    – Stu Pegg
    Feb 29, 2012 at 19:08

3 Answers 3


The SPList.BaseTemplate property tells you what list definition was used to create a given list.

Also, LINQ is by far the most efficient way to query all the lists in your site -- and this could obviously be extrapolated to query all lists within an entire site collection too (see Example 2 here). Creating nested "foreach" loops to manually enumerate all your sites, webs and lists can be very onerous on your system, be warned!

Here is some sample code to get you started:

var obsoleteLists = SPContext.Current.Web.Lists.Cast<SPList>().Where(l => (int)l.BaseTemplate == 10000);

foreach (SPList list in obsoleteLists) 
    Console.WriteLine("The {0} list was created using the {1} definition.", list.Title, list.BaseTemplate);

NOTE: This code assumes that your custom list definition has an ID of 10000. You could replace this with any of the built-in SPListTemplateType values if you were querying for any OOTB list types, e.g. SPListTemplateType.Announcements

  • A quick glance in SPM seems to indicate that BaseTemplate is blank for all lists created with any custom list definition; hence I'd ruled it out before. However, this appears to be because SPM is attempting to convert it to the enumeration. Further digging in Server Explorer shows the true stored ID value. You sir, are my saviour. :)
    – Stu Pegg
    Mar 1, 2012 at 7:37
  • +1 for good answer but "Also, LINQ is by far the most efficient way to query all the lists in your site!" Are you sure about that? Whats happening in the background? I suspect that its doing exactly the same as a for loop over entire collection - LINQ can only be more efficient for somemthing like SQL/CAML where the LINQ operator can be converted into something the underlying store can work with - sharepointblues.com/2010/09/08/…
    – Ryan
    Mar 1, 2012 at 8:02
  • This SO post explains it well - stackoverflow.com/questions/4267783/…
    – Ryan
    Mar 1, 2012 at 8:07
  • There are bucketloads of posts and articles on the web with comparisons of foreach loops vs linq queries. The results are almost always contradictory though so it probably depends on the situation in which you're using the linq/loop. Perhaps I was a "little" excited when I disclaimed that LINQ is always faster, but I generally tend to place more faith in Microsoft's LINQ developers and testers than I do in my own unit tests. Either way, the question above is about code that will only ever run once, so inthat case it's best to go down the path of whichever is easiest to read 'n write.
    – user4545
    Mar 1, 2012 at 8:17
  • @Ryan: At this point I'd be happy even if the answer used COM.
    – Stu Pegg
    Mar 1, 2012 at 8:19

You should be able to tweak this code to get what you are looking for.


Good luck.

  • Thanks, but that article appears to fetch the list's fields (not properties).
    – Stu Pegg
    Feb 29, 2012 at 15:28

this may be of help to get you started - Viewing SharePoint properties as lists, tables and CSV in PowerShell

You can also dig into the list properties using SPManager.

[UPDATE] from first link item -

$web = Get-SPWeb http:/fooSite/
$list = $web.Lists["fooList"] 
$list  #this would give you all the properties including the TemplateFeatureId, SchemaXML, BaseTemplate, PropertiesXML, ServerTemplate, etc..
  • If I was having difficulties retrieving properties in PowerShell in general, then perhaps. However, that article doesn't even mention list definitions as far as I can tell and as you can see from my code sample, I'm using the Object Model...
    – Stu Pegg
    Feb 29, 2012 at 15:39
  • SPM is a great little tool; I used it to find the ServerTemplate attribute I mentioned above. But unfortunately I can't integrate with it programmatically.
    – Stu Pegg
    Feb 29, 2012 at 15:44
  • TemplateFeatureId could be useful in some circumstances, but unfortunately there is more than one list definition in the feature in my case. Here's the OM equivalent for anyone who would find it useful: msdn.microsoft.com/en-us/library/…
    – Stu Pegg
    Feb 29, 2012 at 15:57
  • If the PowerShell version of the object does indeed include the ServerTemplate property you say it does, then it is unique to Powershell, as there is no equivalent OM property.
    – Stu Pegg
    Feb 29, 2012 at 16:00
  • a PowerShell script output showing ServerTemplate: ...FeatureId="00bfea71-de22-43b2-a848-c05709900100" ServerTemplate="100" Created="20120208 12:33:41" Modified="20120208 12:34:06" . Feb 29, 2012 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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