Wednesday, March 18, 2015

How To Delete Sharepoint List using visual studio console app with server object model?


First Create a Console application in Visual studio like this

file->new project->console application


now add sharepoint dell to this solution like this

right click on the references->search about sharepoint from the top right search bar->check it and click ok


now write the programm like this



using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Deletesharepointlist
{
    class Program
    {
        static void Main(string[] args)
        {
            string siteurl = "http://winserver2012:10007/sites/Procurement";
            var site = new SPSite(siteurl);
            var web = site.OpenWeb();
            web.AllowUnsafeUpdates = true;
            var list = web.Lists["MyList"];
            //list.Title = "MyList";
            list.Delete();
            web.AllowUnsafeUpdates = false;
            web.Dispose();
            site.Dispose();
            Console.ReadKey();
        }
    }
}

No comments:

Post a Comment