1

I know how to create lists with Visual Studio.

I need hint on how to create the custom list named 'test' with Title, URL and an boolean field only on the RootWebs of every site collection the feature is deployed and activated on.

variable
  • 4,473
  • 13
  • 75
  • 139

1 Answers1

2

Add the RootWebOnly="true" property to your custom list. The Feature with the Custom List must be scoped to Site.

<ListInstance Title="My custom list"
            FeatureId="00BFEA71-DE22-43B2-A848-C05709900100"
            TemplateType="100"
            Id="MyCustomList"
            Description="Simple custom list sample."
            Url="Lists/MyCustomList"
            OnQuickLaunch="true"
            RootWebOnly="true" />
George Norberg
  • 1,315
  • 3
  • 13
  • 33
  • Should I scope this feature to web or site collection level? – variable Apr 08 '14 at 06:40
  • By default I can see that it is scoped at web level. Why site ? can you tell me. – variable Apr 08 '14 at 06:41
  • Here's a link that explains the different scopes: http://sharepoint.stackexchange.com/questions/27436/explain-it-to-me-sharepoint-deployment-scope-solution-and-features – George Norberg Apr 08 '14 at 06:43
  • Can you also tell me whether the above code needs (ROOTWEBONLY) to go in the elements.xml file of the list or the list instance? – variable Apr 08 '14 at 06:45
  • Well, if i remember correctly, a list instance must be site scoped and it will be available on the site collection. The RootWebOnly property makes it so that it will just be available on the Root. – George Norberg Apr 08 '14 at 06:50
  • Depends if you just have a List instance or a List Definition. The Property is available on both. – George Norberg Apr 08 '14 at 06:53
  • In the VS I can see 2 elements.xml file. 1 is under the listname and one under the listname instance – variable Apr 08 '14 at 07:00
  • a custom list should have a Elements.xml and one SharePointProjectItem.spdata. Sorry cant help you there. Since you have a custom list it doesn't have a Definition so. Google how to create a Custom list. – George Norberg Apr 08 '14 at 07:03
  • Dude, I did create a custom list, I created a SP project. Then under that I did a add item -> List. Then created necessary columns. Now under the project I can see my item (listname) containing elements.xml file. Also within this item there is listnameinstance (this also contains elements.xml) – variable Apr 08 '14 at 07:08
  • Great! now in the elementsxml just add the property in the listinstance tag. – George Norberg Apr 08 '14 at 07:10
  • As I have mentioned in my comment above, I can see 2 elements.xml files. One is in the listname->elements.xml and one is under listname->listnameinstance-elements.xml – variable Apr 08 '14 at 07:12
  • My guess is that you have a list Definition: listname->listnameinstance-elements.xml and a List Instance: listname->elements.xml – George Norberg Apr 08 '14 at 07:14
  • When you create the Custom list, set "Create a list instance based on an existing list template" to Custom List. – George Norberg Apr 08 '14 at 07:15
  • 1
    I guess then it will no longer be customizable. Anyways I did the change on the listnameinstance->elements.xml and it worked. – variable Apr 08 '14 at 07:18
  • I have 1 question. Not related maybe. But, suppose if I say RootWebOnly='FALSE'. Then, can you tell me what will happen? – variable Apr 09 '14 at 06:53
  • This property is false by default for lists. It will "do nothing". Instead of just being on the root (If it's true) the list will be available "everywhere" on the Site Collection. – George Norberg Apr 09 '14 at 07:33
  • So the list will get created for every subsite. Right? – variable Apr 09 '14 at 07:37
  • Not sure. I believe so. – George Norberg Apr 09 '14 at 07:43