In this small tutorial i shall demonstrate how to hook up C# to use the Windows Sharepoint Services API (WSS). It’s fairly simple and straightforward. You need the following:

  1. A machine running Windows server 2003/08 with Sharepoint installed.
  2. Microsoft Visual Studio 2005.
  3. About 15 minutes.

For the purposes of this example, we will create a small console application that will list all the sites of a Sharepoint site. First of open Visual Studio and create a new Visual C# console application. Next step is adding the reference to the WSS API on our project. To do so, you can go on the explorer window, right click on the “References” and click “Add Reference…”. On the window that will show up choose “Windows Sharepoint Services” dll from the .NET packages.

Once this step is done, off to the code:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            SPSite root = new SPSite("http://testsite");//this is the URL to the sharepoint site we want to connect to
            foreach (SPWeb site in root.AllWebs)//looping through the collection of the sites
            {
                Console.WriteLine(site.Name);
            }
            Console.ReadLine();
        }
    }
}

From here on, sky is the limit! You can view a documentation of the WSS API here.