Click here to Skip to main content
13,554,737 members
Click here to Skip to main content
Add your own
alternative version


31 bookmarked
Posted 7 Jun 2007
Licenced CPOL

Using SharePoint Web Services to Explore Document Libraries

, 8 Jul 2007
Rate this:
Please Sign up or sign in to vote.
Using SharePoint Web Services to explore document libraries.

Screenshot - Img.gif


SharePoint is a recognized technology standard for company infrastructure organizations. It has wide functionality, and allows to store different information in one single place. However, sometimes this information needs to be accessed from an application. In this article, I will discuss the possibility to retrieve data from SharePoint using its WebServices. I will concentrate on the document libraries.


SharePoint Server structures information by WebSites. Each WebSite has many Lists. Lists are used to store concrete data using ListItems: links to files, contacts, appointments, etc. ListItems have fields with necessary values. The user is able to customize these fields to store data. In the following section, I will show a general mechanism for retrieving data.

First of all, it is necessary to add a reference to SharePoint Services. They are accessible from the following URL: http://server-name/Site-Name/_vti_bin/service-name.asmx. For our purposes, we will use two of them: webs.asmx and lists.asmx.

Another important feature is that SharePoint Services are scope dependent, so if you want to retrieve a List from site S1, you should use the following WebSite: http://server-name/S1/_vti_bin/lists.asmx, and so on.

Retrieving WebSites

// Get Web Sites
private static void GetSites(string url, string login, string password)
    Webs service = new Webs();
    service.PreAuthenticate = true;
    service.Credentials = new System.Net.NetworkCredential(login, password);
    service.Url = url + @"/_vti_bin/webs.asmx";

    XmlNode sites = null;

        sites = service.GetWebCollection();

    foreach (System.Xml.XmlNode site in sites.ChildNodes)

        GetLists(site.Attributes["Url"].Value, login, password);
        GetSites(site.Attributes["Url"].Value, login, password);

Retrieving a WebSite List

//Get Web Site Lists  
private static void GetLists(string url, string login, string password)
    //List WebService 
    Lists ls = new Lists();
    ls.PreAuthenticate = true;
    ls.Credentials = new NetworkCredential(login, password);
    ls.Url = url + @"/_vti_bin/lists.asmx";

    foreach (XmlNode list in ls.GetListCollection().ChildNodes)
        //Check whether list is document library
        if (Convert.ToInt32(list.Attributes["ServerTemplate"].Value) != 0x65)

        string title = list.Attributes["Title"].Value;
        string listUrl = list.Attributes["DefaultViewUrl"].Value.Replace(
                                         "/Forms/AllItems.aspx", string.Empty);

        char[] separator = new char[] { '/' };
        string listPath = url.Substring(0, url.LastIndexOf('/'));

        Console.WriteLine(listPath + listUrl + "/" + title);
        AddListsItems(url, title, login, password);

Points of Interest

Sorry for being so concise. I'm quite new to SharePoint, but this task gave me some trouble. So I decided to post my solution.

The article will be further updated to show how to retrieve list items basing on SharePoint XML Queries.


  • 12 June 2007: Added example application.
  • 7 June 2007: First version.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Petro Protsyk
Netherlands Netherlands
Please visit my website for more articles

I'm software developer & Ph.D. student

You may also be interested in...


Comments and Discussions

BugThe code in Document Libraries with two levels fails Pin
fcojavilg23-Feb-12 3:45
memberfcojavilg23-Feb-12 3:45 
GeneralMy vote of 4 Pin
sparrow8821-Dec-11 2:06
membersparrow8821-Dec-11 2:06 
GeneralAppreciate Pin
SolarCell13-Apr-11 23:28
memberSolarCell13-Apr-11 23:28 
GeneralRe: Appreciate Pin
sparrow8821-Dec-11 2:08
membersparrow8821-Dec-11 2:08 
QuestionAllways returns parent site Lists instead of subsites. Pin
Member 9650879-Nov-09 12:58
memberMember 9650879-Nov-09 12:58 
GeneralAccessing sharepoint from an excel workbook in a local machine Pin
Member 63670353-Jul-09 8:13
memberMember 63670353-Jul-09 8:13 
GeneralConnecting to server machine failed Pin
afilho17-Jun-09 3:31
memberafilho17-Jun-09 3:31 
Generaldispaly images from sharepoint to website Pin
T.Ashraf8-Jun-08 13:41
memberT.Ashraf8-Jun-08 13:41 
GeneralRe: dispaly images from sharepoint to website Pin
T.Ashraf12-Jun-08 10:24
memberT.Ashraf12-Jun-08 10:24 
QuestionRe: dispaly images from sharepoint to website Pin
mangia25-Nov-08 12:48
membermangia25-Nov-08 12:48 
I too have a need to read images and HTML text content from SharePoint via web services (WSS not MOSS). Have you, or anyone else found a nice example of how to fetch data from SharePoint (beyonds list of items).

Chris Mangiapane. MCSD

AnswerRe: dispaly images from sharepoint to website Pin
T.Ashraf25-Nov-08 12:52
memberT.Ashraf25-Nov-08 12:52 
GeneralRe: dispaly images from sharepoint to website [modified] Pin
mangia26-Nov-08 6:56
membermangia26-Nov-08 6:56 
GeneralRe: dispaly images from sharepoint to website Pin
T.Ashraf27-Nov-08 2:30
memberT.Ashraf27-Nov-08 2:30 
GeneralThanks - This really kickstarted my work! Pin
Chris Doherty30-Mar-08 14:43
memberChris Doherty30-Mar-08 14:43 
GeneralWSS version Pin
T. Smaavik5-Sep-07 3:59
memberT. Smaavik5-Sep-07 3:59 
GeneralRe: WSS version Pin
Extrim5-Sep-07 4:18
memberExtrim5-Sep-07 4:18 
GeneralA suggestion... Pin
HyperX10-Jun-07 4:05
memberHyperX10-Jun-07 4:05 
GeneralRe: A suggestion... Pin
Extrim10-Jun-07 20:15
memberExtrim10-Jun-07 20:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01-2016 | 2.8.180515.1 | Last Updated 9 Jul 2007
Article Copyright 2007 by Petro Protsyk
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid