Geeks With Blogs

News Sharepoint Server 2010, MS SQL Server 2008 R2 and Windows Server 2008 R2 Better Together.
Read the whitepaper here:MSDN

The opinions expressed herein are my personal opinions and does not represent the opinions of my employer.

free counters

mike's Blog (mr. NICE guy) "Talent, Ambition and Work Ethics ~ my way of being a SharePoint Mutt"

In this post I’m going to demonstrate how to create SharePoint List and also Insert Items on the List from a Windows Forms Application.

1. Open Visual Studio and create a new project. On the project template select Windows Form Application under C#.

2. In order to communicate with Sharepoint from a Windows Forms Application we need to add the 2 Sharepoint Client DLL located in c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI. 

3. Select the Microsoft.Sharepoint.Client.dll and Microsoft.Sharepoint.Client.Runtime.dll. (Your solution should look like the one below)


4. Open the Form1 in design view and from the Toolbox menu add a button on the form surface. Your form should look like the one below.


5. Double click the button to open the code view. Add Using statement to reference the Sharepoint Client Library then create method for the Create List. Your code should like the codes below.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Security;
using System.Windows.Forms;
using SP = Microsoft.SharePoint.Client;

namespace ClientObjectModel
    public partial class Form1 : Form
        // url of the Sharepoint site
        const string _context = "urlofthesharepointsite";

        public Form1()

        private void Form1_Load(object sender, EventArgs e)

        private void cmdcreate_Click(object sender, EventArgs e)

                // declare the ClientContext Object
                SP.ClientContext _clientcontext = new SP.ClientContext(_context);
                SP.Web _site = _clientcontext.Web;

                // declare a ListCreationInfo
                SP.ListCreationInformation _listcreationinfo = new SP.ListCreationInformation();

                // set the Title and the Template of the List to be created
                _listcreationinfo.Title = "NewListFromCOM";
                _listcreationinfo.TemplateType = (int)SP.ListTemplateType.GenericList;

                // Call the add method to the ListCreatedInfo
                SP.List _list = _site.Lists.Add(_listcreationinfo);

                // Add Description field to the List
                SP.Field _Description = _list.Fields.AddFieldAsXml(@"
                                    <Field Type='Text'
                                    </Field>", true, SP.AddFieldOptions.AddToDefaultContentType);

                // declare the List item Creation object for creating List Item
                SP.ListItemCreationInformation _itemcreationinfo = new SP.ListItemCreationInformation();

                // call the additem method of the list to insert a new List Item
                SP.ListItem _item = _list.AddItem(_itemcreationinfo);
                _item["Title"] = "New Item from Client Object Model";
                _item["Description"] = "This item was added by a Windows Forms Application";
                // call the update method

                // execute the query of the clientcontext
                // dispose the clientcontext
                MessageBox.Show("List Creation Successfull");
            catch(Exception ex)
                MessageBox.Show("Error creating list" + ex.ToString());




6. Hit F5 to run the application. A message will be displayed on the screen if the operation is successful and also if it fails.

7. To make that the operation of our Windows Form Application has really created the List and Inserted an item on it. Let’s open our SharePoint site. Once the SharePoint is open click on the Site Actions then View All Site Content.


7. Click the List to open it and check if an Item is inserted.


That’s it. Hope this helps. Winking smile

Posted on Wednesday, April 11, 2012 8:26 AM Client Object Model | Back to top

Comments on this post: How to Create SharePoint List and Insert List Item programmatically from a Windows Forms Application.

# re: How to Create SharePoint List and Insert List Item programmatically from a Windows Forms Application.
Requesting Gravatar...
you've got a nice article, very informative, we appreciate it, please keep on posting articles, we''ll come back and read more articles.

Left by MP3 Music Free Download Sites on Apr 11, 2012 10:26 PM

# re: How to Create SharePoint List and Insert List Item programmatically from a Windows Forms Application.
Requesting Gravatar...
Create Document Library programatically in sharepoint 2010
Left by AAAA on Mar 08, 2014 1:33 PM

Your comment:
 (will show your gravatar)

Copyright © Michael M. Bangoy | Powered by: