Pages

Wednesday, September 3, 2014

Create Discussion Board list definition through Visual Studio 2012 for SharePoint 2013

Introduction

There was a requirement to create a discussion board list definition through visual studio. So that our client can be able to create list instance with some customization.

Problem Background

We tried to create content type by inheriting Discussion and then created a custom list definition using created content type. But it was not same as the out of the box discussion board – We couldn’t get the reply page and the views as in the ootb.

Solution

  • Create a new SharePoint solution
  • Add a content type inheriting from Discussion
    • Right Click on the project –> Add –> New Item –> Content Type –> Name it (I have named it as DisBoardCT) –> Click Add –> Select Discussion from Content type setting page

image

  • Create a List
    • Right Click on the project –> Add –> New Item –> List –> Click Add select the first option from Choose List Setting Page

image

  • Add the above created content type to our list

image

image

Now you list definition is ready. But this will not work as the out of the box discussion board.

  • Now you have to change the schema.xml
    • Go to the OOTB list definition usually the location is C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\FEATURES\DiscussionsList\Discuss
    • Copy the content in schema.xml and paste on our schema.xml in the visual studio
    • Get the Content type ID which we created.

    image

    • Replace the content type ID in schema.xml with our ID. There will be couple instances of the default content type. “0x012002”image
    • Once you change the content type in schema.xml the default content type in will be set to our custom content type. Please verify

image

  • Change the Type
    • Change the Type to 108 and the Image to

      Image="/_layouts/15/images/itdisc.png?rev=23"/>

      image

  • Change the Template type to 108 in list instance elements file.

image

image

  • Now deploy the solution and you should be able to get see the our custom discussion board list definition.

Conclusion

I have created a sample and you may download it here.

https://drive.google.com/file/d/0ByEnOE8DAdvhWUJ4ektWR2RBQXc/view?usp=sharing

2 comments:

  1. Perfect!
    ...I was editing the content type name in the schema as well, and it broke down everything: you solved it for me, thanks!!!

    ReplyDelete
  2. Awesome article .thanks for sharing ..works like charm ..

    ReplyDelete