Welcome to a blog on how to create an announcement list in SharePoint 2013 programmatically using a console application. We will use Visual Studio to create a list in SharePoint 2013.
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)
- {
-
- ClientContext context = new ClientContext("http://devtest /SPTests/");
- Web web = context.Web;
-
- ListCreationInformation createlist = new ListCreationInformation();
- createlist.Title = "Announcements";
- createlist.Description = "My Custom Announcements";
-
- createlist.TemplateType = (int)ListTemplateType.Announcements;
-
- web.Lists.Add(createlist);
- context.ExecuteQuery();
- Console.WriteLine("Announcements List Created");
- Console.ReadKey();
- }
- }
- }
- Run the code and your custom announcement list will be created.
Keep reading & keep learning!