How To Create An Announcement List In Sharepoint 2013 Programmatically

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
    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  
    18. ClientContext context = new ClientContext("http://devtest /SPTests/");  
    19. Web web = context.Web;  
    20. //provide the list creation information as Title and Description  
    21. ListCreationInformation createlist = new ListCreationInformation();  
    22. createlist.Title = "Announcements";  
    23. createlist.Description = "My Custom Announcements";  
    24. //choose a template as Generic List.  
    25. createlist.TemplateType = (int)ListTemplateType.Announcements;  
    26. //add list to SharePoint  
    27. web.Lists.Add(createlist);  
    28. context.ExecuteQuery();  
    29. Console.WriteLine("Announcements List Created");  
    30. Console.ReadKey();  
    31. }  
    32. }  
    33. }
  • Run the code and your custom announcement list will be created.

     
Keep reading & keep learning!
Ebook Download
View all
Learn
View all