Creating a Basic SharePoint Foundation Client Application

SharePoint 2010

Last modified: August 03, 2010

Applies to: SharePoint Foundation 2010

Available in SharePoint Online

To create a .NET managed client application that uses the client object model, you must set references to two client library DLLs-- Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll. You can copy these DLLs from the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\ISAPI folder of the server that runs Microsoft SharePoint Foundation 2010 to the remote computer on which you create the application.

The following programming task steps through the procedure of creating a basic console application in Microsoft Visual Studio that uses objects in the Microsoft.SharePoint.Client namespace to return Web site properties.

  1. On the File menu, point to New and click Project.

  2. In the New Project dialog box, select Visual Basic or Visual C# in the Installed Templates panel. Select Windows and then Console Application. Choose .NET Framework 3.5 from the drop-down at the top of the center panel. Type a name and location for the project in the Name and Location boxes. Then click OK.

  3. In Windows Explorer, copy the two DLLs from the server's %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\ISAPI folder into the top-level folder of your console application.

  4. Right-click the project in Solution Explorer, click Add Reference, and in the Add Reference dialog box, click the Browse tab and navigate to the folder where you copied Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll. Select the two DLLs, and click OK.

  5. The following example returns and displays the title of the Web site at the URL that is specified in the ClientContext() constructor. The Load<T>(T, []) method specifies which object to retrieve from the server, which in this case is the Web site, and ExecuteQuery() performs the query. Because the Web site object is loaded, all its default properties become available for display at the console. For information about properties that are not available by default when you load and object or collection, see Data Retrieval Overview.

    using System;
    using Microsoft.SharePoint.Client;
    namespace Microsoft.SDK.SharePointServices.Samples
        class DisplayWebTitle
            static void Main()
                ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection/MyWebSite");
                Web oWebsite = clientContext.Web;  
                Console.WriteLine("Title: {0} Created: {1}", oWebsite.Title, oWebsite.Created);
  6. Press F5 to run the application and display the title and created date of the Web site at the console.