Wednesday, March 18, 2015

How To Update a SharePoint list using server object model in visual studio with console application

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;
using Microsoft.SharePoint.Client;

namespace UpdateList
{
    class Program
    {
        static void Main(string[] args)
        {
            //make changes based on your site url
            string siteurl = "http://winserver2012:10007/sites/Procurement";
            var site = new SPSite(siteurl);
            var web = site.OpenWeb();
            web.AllowUnsafeUpdates = true;
            var list = web.Lists["My List"];
            list.Title = "MyList";
            list.Update();
            web.AllowUnsafeUpdates = false;
            web.Dispose();
            site.Dispose();
            Console.ReadKey();
        }
    }
}

No comments:

Post a Comment