Question

I am creating list definitions.Now what I want to create some folder when We create Elements.xml for list definition.

Thanks in advance

Was it helpful?

Solution

Add the following code in Elements.xml to create folder in list.

<Data>
           <Rows>
        <Row>
          <Field Name="ContentTypeId">0x0120004F994A3C0FF76546A528DA0D4B515898</Field>
          <Field Name="FileLeafRef">MyTestFolder</Field>
          <Field Name="Title">MyTestFolder</Field>
          <Field Name="FSObjType">1</Field>
        </Row>
      </Rows>
    </Data>

Refer to following articles for more information

http://msdn.microsoft.com/en-IN/library/ms478860(v=office.14).aspx

http://johnlearnt.blogspot.in/2012/09/provision-folder-inside-document-library.html

Also, you can do it from an event receiver when the list is created:

Create an event receiver (ListAdded) for the library definition (Dev Center). Add code to create the folder structure.

SPList list = web.Lists.TryGetList("ListTitle");

SPFolderCollection folderColl = list.RootFolder.SubFolders;

SPFolder newFolder = folderColl.Add(FolderUrl);

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top