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


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

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

Refer to following articles for more information



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 you have read our privacy policy.

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