Click here to Skip to main content
6,629,885 members and growing! (24,442 online)
Email Password   helpLost your password?
Enterprise Systems » SharePoint Server » General     Intermediate

Using SharePoint Web Services to Explore Document Libraries

By Extrim

Using SharePoint Web Services to Explore Document Libraries
C#, Windows, .NET, Visual Studio, Dev
Posted:7 Jun 2007
Updated:8 Jul 2007
Views:46,847
Bookmarked:17 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
11 votes for this article.
Popularity: 2.99 Rating: 2.88 out of 5
3 votes, 27.3%
1
2 votes, 18.2%
2
1 vote, 9.1%
3
1 vote, 9.1%
4
4 votes, 36.4%
5

Demo - 144.4 KB

Source - 32 KB

Screenshot - Img.gif

Introduction

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

Background

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 has fields with necessary values. The user is able to customize this fields to store data.
In the following section I will show general mechanism for retrieving data.

First of all it is necessary to add reference to SharePoint services. They are accessible from the following urls 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 I you want to retrieve the List from the site S1 you should use following WS: http://server-name/S1/_vti_bin/lists.asmx, and so on.

Retrieving Web Sites:

//

// 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;

            try
            {
                sites = service.GetWebCollection();
            }
            catch
            {
                return;
            }

            foreach (System.Xml.XmlNode site in sites.ChildNodes)
            {
                Console.WriteLine(site.Attributes["Url"].Value);

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

Retrieving Web Site 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)
                {
                    continue;
                }

                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 made me some troubles. So I've decided to post it.

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

History

  • 12 June 2007 (Example Application)
  • 7 June 2007

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Extrim


Member
Please visit my website for more articles

I'm software developer & Ph.D. student

Occupation: Software Developer (Senior)
Location: Ukraine Ukraine

Other popular SharePoint Server articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 14 of 14 (Total in Forum: 14) (Refresh)FirstPrevNext
QuestionAllways returns parent site Lists instead of subsites. PinmemberMember 96508713:58 9 Nov '09  
GeneralAccessing sharepoint from an excel workbook in a local machine PinmemberMember 63670359:13 3 Jul '09  
GeneralConnecting to server machine failed Pinmemberafilho4:31 17 Jun '09  
Generaldispaly images from sharepoint to website PinmemberT.Ashraf14:41 8 Jun '08  
GeneralRe: dispaly images from sharepoint to website PinmemberT.Ashraf11:24 12 Jun '08  
QuestionRe: dispaly images from sharepoint to website Pinmembermangia13:48 25 Nov '08  
AnswerRe: dispaly images from sharepoint to website PinmemberT.Ashraf13:52 25 Nov '08  
GeneralRe: dispaly images from sharepoint to website [modified] Pinmembermangia7:56 26 Nov '08  
GeneralRe: dispaly images from sharepoint to website PinmemberT.Ashraf3:30 27 Nov '08  
GeneralThanks - This really kickstarted my work! PinmemberChris Doherty15:43 30 Mar '08  
GeneralWSS version PinmemberT. Smaavik4:59 5 Sep '07  
GeneralRe: WSS version PinmemberExtrim5:18 5 Sep '07  
GeneralA suggestion... PinmemberHyperX5:05 10 Jun '07  
GeneralRe: A suggestion... PinmemberExtrim21:15 10 Jun '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 8 Jul 2007
Editor:
Copyright 2007 by Extrim
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project