DWS


Table of Contents

Sadly in WSS 3/MOSSS 2007 the Client side API for SharePoint is somewhat lacking compared to the powerful and well documented Server side Object Model, luckily Visual Studio 2008 makes it fairly easy to perform basic tasks with Document Libraries from the client end. This guide will show you how to use the basic Visual Studio Web Service reference tool to add and access the DWS API.

_vti_bin/DWS.asmx
The Document Workspace Service lives in the _vti_bin directory of each SharePoint site and provides the ability to create folders, delete folders as well as manipulating actual document workspaces. For subsites in a SharePoint instance the DWS can be accessed from http://sp-server/subsite/_vti_bin/DWS.asmx

Making Visual Studio aware of the DWS
First we need to have Visual Studio build our class from the DWS web service, to do this first go to your Solution Explorer and right click on your project and select Add Service Reference

Click on the Advanced button in the dialog that appears.

Click on the Add Web Reference button.

Enter in the address of your SharePoint web site (or subsite) plus the /_vti_bin/DWS.asmx URI and click Go to discover the Web Service

Visual Studio will render the web page that SharePoint provides with a list of all available methods that can be used with the service. On the right side give the Web Service a useful name and click Add Reference.

Your Web Service is accessible programmatically.

Changing the DWS URI from App.config
If you wish to change your Document Library location without having to open Visual Studio, you may edit your application's app.config file to change the DWS location. The DWS location is located in applicationSettings > Project_Name.Properties.Settings > setting name="Test_Console_myDWSService_Dws" > value.

Creating a Folder in an existing Document Library
Depending on your preference you can use the WebDAV method to create folders (MKCOL) or the DWS.CreateFolder("Document Library/new folder") method. In this example we will create a folder in the Document Library: Test Library which is located at the root of the SharePoint site. http://localhost/Test Library.

First construct an instance of the DWS object using the code and also pass through our current credentials (as this is a web service)

Construct instance
myDWSService.Dws dwsInstance = new Test_Console.myDWSService.Dws();
dwsInstance.Credentials = System.Net.CredentialCache.DefaultCredentials;

The next step is to call the CreateFolder method, which returns a String object which is the XML response from the Server. The URL must include the Document Library URI name and the folder we wish to create, which may be a subfolder of a folder that already exists.

CreateFolder call
String response = dwsInstance.CreateFolder("Test Library/new_folder");

If you wish to create folders recursively, it would be best to split/explode a String by the forward slash and create each folder recursively as you go deeper into the hierarchy.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.



Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Hosted generously by CustomWare