3

I need to add some items to sharepoint list definition, so I need to have the list with columns and items, and then allow users to create the list from the UI. How do I include items in list definition?

Jacky
  • 319
  • 4
  • 12
  • You can use custom list template for that. It will be available in the add new app section. – Dikesh Gandhi Nov 29 '16 at 04:32
  • How do I do that in visual studio? – Jacky Nov 29 '16 at 04:39
  • You need to create Custom Columns, Add List Definition and List Instance. In the list instance you can Add the Items. – Ram Nov 29 '16 at 04:40
  • This link will give you some idea: http://sharepoint.stackexchange.com/questions/33576/listinstance-with-predefined-data-prevent-adding-records-to-list-with-same-name – Dikesh Gandhi Nov 29 '16 at 04:41

2 Answers2

4

You can do this as follow-

  • Add Site Columns to the custom Solution in the Visual Studio.
  • Add The Content Type if Required.
  • Create List Definitions & Associate the Content Type to the List (If required).
  • Add the List Items in the List Instance by default. In the Items Here
  • Deploy this solution & you can see the List with default items.

For the reference Click Here & Here & Here.

This Link will give in details step by step with the Screenshots.

Hope this will help you.

Ram
  • 2,444
  • 2
  • 19
  • 38
  • I know how to do all of this. I don't want to create the list, users will create the lists with predefined items .. – Jacky Nov 29 '16 at 05:31
  • Yes, You just create this & save it as an List Template. User need to click => Add an App => Select the List Template Which you have created & uploaded to Template Gallery. Then all the default items will be created on the creation of List by any one of user. – Ram Nov 29 '16 at 05:36
  • I need something in visual studio, as said in my question, I need it in list definition to be packaged, I don't want any manual work .. – Jacky Nov 29 '16 at 05:48
  • I have not yet done this with Visual Studio, But might be there is something to do. But as I know the List Template you need to create it as above steps and while any User create => Add an App => that time user can get the default items which are added in the list instance. – Ram Nov 29 '16 at 06:52
  • Hey, If you got answer please post it! – Ram Dec 01 '16 at 18:49
  • Hi Ram. I didn't actually. – Jacky Dec 02 '16 at 01:32
  • Cool, I'll try it & get back to Answer if I can! Hope for the best! We can! – Ram Dec 02 '16 at 04:27
3

If you add list using ListInstance then you can add items using ListInstance file:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <ListInstance Title="LinkList" OnQuickLaunch="TRUE" TemplateType="170" FeatureId="Your feature id" Url="Lists/LinkList" Description="Your description">
<Data>
  <Rows>
    <Row>
      <Field Name="Title">About</Field>
      <Field Name="Description">Description</Field>
      <Field Name="LinkLocation">http://testlink.com</Field>
      <Field Name="BackgroundImageLocation">
        /sites/Images/tile_about.png</Field>
      <Field Name="LaunchBehavior">New tab</Field>
      <Field Name="Order">2</Field>
    </Row>
  </Rows>
</Data>
</ListInstance>  
</Elements>
Akshay Dattatray Nangare
  • 3,392
  • 9
  • 59
  • 105