For a recent project we needed to create record libraries automatically through a deployment script. This was achieved using the following piece of code:
using (SPSite site = new SPSite("http://sp/")) { using (SPWeb recordsite = site.OpenWeb("/records")) //records site url { foreach (SPListTemplate templ in recordsite.ListTemplates) { if (templ.Type_Client == 1302) { SPListCollection listcol = recordsite.Lists; Guid nListGuid = listcol.Add(library[0], "", templ); SPList nList = recordsite.Lists[newListGuid]; nList.OnQuickLaunch = true; nList.Update(); break; } } } }
The list template is not available in the SPListTemplateType enumerable list but is available by iterating through the available templates and finding it by it’s ID 1302. The In Place Records Management feature (ID: da2e115b-07e4-49d9-bb2c-35e93bb9fca9) needs to be enabled in the site collection to be able to create these libraries.