<CharlieDigital/> Programming, Politics, and uhh…pineapples

8Feb/12Off

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.

<?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.

Posted by Charles Chen

Filed under: SharePoint Comments Off
Comments (2) Trackbacks (0)
  1. 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.


Trackbacks are disabled.