How To Create A Discussion Board In SharePoint 2013 Programmatically

Welcome to a blog on how to create a discussion board in SharePoint 2013 programmatically using a console application. We will use Visual Studio to create Discussion Board in SharePoint 2013 site.
 
Let’s see how to do it.
  • Open you Visual Studio
  • Select New Project

  • Select Console Application.
  • Add the references
    Microsoft.SharePoint dll and Microsoft.SharePoint.Client dll
  • Paste the code below under Program.cs.
Code 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Security;  
  5. using System.Net;  
  6. using System.Text;  
  7. using System.Web;  
  8. using System.Data;  
  9. using Microsoft.SharePoint;  
  10. using Microsoft.SharePoint.Client;  
  11. namespace ConsoleApplication1  
  12. {  
  13. class Program  
  14. {  
  15. static void Main(string[] args)  
  16. {  
  17. #Get the web here    
  18. ClientContext context = new ClientContext("Your site url here");  
  19. Web web = context.Web;  
  20. ListCreationInformation disBoard = new ListCreationInformation();  
  21. #Provide a name and description to your Discussion board.   
  22. disBoard.Title = "My Discussion Board";  
  23. disBoard.Description = "My Discussion Board";  
  24. disBoard.TemplateType = (int)ListTemplateType.DiscussionBoard;  
  25. web.Lists.Add(disBoard);  
  26. #Execute the code   
  27. context.ExecuteQuery();  
  28. Console.WriteLine("Discussion Board Created");  
  29. Console.ReadKey();  
  30. }  
  31. }  
  32. }   
  • Run the code and your Discussion Board will be created.
 

Keep reading & keep learning!