In this article we will be seeing how to create, update and delete SharePoint
2010 lists using Client Object Model (through both C# code and PowerShell
script).
Assembly: Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Namespace: Microsoft.SharePoint.Client
//Creating the list using Client Object Model:
// C# code:
using
System;
using
Microsoft.SharePoint;
using
Microsoft.SharePoint.Client;
namespace
COM
{
class Program
{
static void
Main(string[] args)
{
string siteUrl=
"http://serverName:31829/sites/Home/";
ClientContext clientContext=new
ClientContext (siteUrl);
Web site = clientContext.Web;
ListCreationInformation
listCreationInfo = new
ListCreationInformation();
listCreationInfo.Title = "COM List";
listCreationInfo.Description = "List
created using COM";
listCreationInfo.TemplateType = (int)ListTemplateType.DocumentLibrary;
List list =
site.Lists.Add(listCreationInfo);
clientContext.ExecuteQuery();
Console.WriteLine("List
is created successfully");
Console.ReadLine();
}
}
}
// PowerShell Script:
$siteUrl="http://serverName:31829/sites/Home/"
$clientContext= [Microsoft.SharePoint.Client.ClientContext,Microsoft.SharePoint.Client,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]
$context=New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
[Microsoft.SharePoint.Client.Web]$site=$context.Web;
$listCreationInfo=New-Object Microsoft.SharePoint.Client.ListCreationInformation
$listCreationInfo.Title="COM List"
$listCreationInfo.Description="List created using COM"
$listCreationInfo.TemplateType=[int][Microsoft.SharePoint.Client.ListTemplateType]::DocumentLibrary;
[Microsoft.SharePoint.Client.List]$list=$site.Lists.Add($listCreationInfo);
$context.ExecuteQuery();
write-host "List is created successfully"
//Deleting the list using Client Object Model:
// C# code:

Gowtham RajamanickamPosted Apr 20, 2015, 3:17 PM
good
Nalaka MalalagamaPosted Jan 9, 2011, 7:02 AM
Hello, I followed your codes and developed a small win app with c# in VS 2010. I wanted to run this app on a client machine (eg: Win 7, Server 2008 or Vista). So, I tried several things... by using a setup, just running only the *.exe file, etc. But, all failed. Please let me know how exactly to do that. Many Thanks. Nalaka