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
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security;
- using System.Net;
- using System.Text;
- using System.Web;
- using System.Data;
- using Microsoft.SharePoint;
- using Microsoft.SharePoint.Client;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- #Get the web here
- ClientContext context = new ClientContext("Your site url here");
- Web web = context.Web;
- ListCreationInformation disBoard = new ListCreationInformation();
- #Provide a name and description to your Discussion board.
- disBoard.Title = "My Discussion Board";
- disBoard.Description = "My Discussion Board";
- disBoard.TemplateType = (int)ListTemplateType.DiscussionBoard;
- web.Lists.Add(disBoard);
- #Execute the code
- context.ExecuteQuery();
- Console.WriteLine("Discussion Board Created");
- Console.ReadKey();
- }
- }
- }
- Run the code and your Discussion Board will be created.
Keep reading & keep learning!