Currently Browsing: Sharepoint

Using Windows Sharepoint Services (WSS) to create a new site

To cut to the chase, the process of creating a new subsite using WSS is as follows:

  1. Connect to the main site using SPSite.
  2. Add the new site using the Add() method on AllWebs collection.
  3. Do all kinds of magic using the newly created site.

Here is a small C# code example:

  1. SPSite rootSite = new SPSite("http://testsite");
  2. SPWeb site = rootSite.AllWebs.Add("testsub");

In order to access this site you need to visit “http://testsite/testsub”. Hope this helps!

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.