Folders and Nested Folders in ListInstances
This took me about 3 hours to figure out so I figure it was worth sharing.
First, I assumed that it was possible given that the .stp file export of a custom list with folders and nested folders seem to work fine. Online, the feedback seems to be a bit different and my early results seemed to confirm it. However, I persisted and after several (and I mean several) tries, I finally got it working.
So I share with you the magic sauce for those times when you want to seed your deployment with hierarchical data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <ListInstance Title="Seed Data" OnQuickLaunch="TRUE" RootWebOnly="TRUE" TemplateType="10000" Url="Lists/SeedData" Description="Seed data"> <Data> <Rows> <Row> <Field Name="ID">1</Field> <Field Name="ContentType">Country</Field> <Field Name="Title">USA</Field> <Field Name="FSObjType">1</Field> </Row> <Row> <Field Name="ID">2</Field> <Field Name="ContentType">State</Field> <Field Name="Title">New Jersey</Field> <Field Name='FileDirRef'>USA</Field> <Field Name="FSObjType">1</Field> </Row> <Row> <Field Name="ID">3</Field> <Field Name="ContentType">County</Field> <Field Name="Title">Mercer</Field> <Field Name="FileDirRef">USA/New Jersey</Field> <Field Name="FSObjType">0</Field> </Row> </Rows> </Data> </ListInstance> </Elements> |
Yes, it was a pretty painful experience to get this figured out, but it was definitely worth it.
You can export all this stuff using Designer without “pretty painful experience”.
Possibly, but for product development, it’s a different story.
I would want to be able to take an extract from an existing system, for example, and transform it into the right XML to automatically populate the list on deployment without having to fuss around with an intermediate step of putting it into a SharePoint list an exporting it first.
I should note that I started by exporting it to a template first and the format that it was in was not compatible with the ListInstance schema. In other words, if I copied the XML from the template, it would not work.