0

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

Thanks in advance

1 Answer 1

1

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);

Your Answer

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

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