Hook up C# with Windows Sharepoint Services (WSS) tutorial

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:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Microsoft.SharePoint;
  5.  
  6. namespace TestApp
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             SPSite root = new SPSite("http://testsite");//this is the URL to the sharepoint site we want to connect to
  13.             foreach (SPWeb site in root.AllWebs)//looping through the collection of the sites
  14.             {
  15.                 Console.WriteLine(site.Name);
  16.             }
  17.             Console.ReadLine();
  18.         }
  19.     }
  20. }

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



2 Responses to “ “Hook up C# with Windows Sharepoint Services (WSS) tutorial”

  1. elijah says:

    man, u got spoiled!

  2. stratosg says:

    Hey man i know… I’ve been walking towards the dark side these days and i realize what i’ve done :( :P

Leave a Reply