Derik Whittaker



Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
Using Sharepoint's Web Services to QueryDocuments.

For the latest thing I am doing at work I need to be able to grab some data from Sharepoint.  I have chosen to do this by consuming SPServices.asmx server that is available.  Because I was not able to find a decent post on the net on how to use/consume this service, I thought I would create my own.  For this post I am going to walk though using the QueryDocuments method.  As I use/consume more methods, I will try to post on those as well.

Before you get started working with the Sharepoint Web Services, I would recommend you download the SDK from here.  I would then suggest you install it and poke around the CHM file.

Service Location

FYI, if you download the SDK, this will NOT install any assemblies on your drive (see my rant about this here). 

You will be able to find the ASMX files on the box with Sharepoint install in the following location.
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI

You will be able to find the ASMX interface via a browser here

All the web services can also be found under each and every sub-site that is created. 

Consuming the service

The purpose of this post is to not teach you how to consume the post, however you will only need to open up VS2005 and do an add Web Reference and you will be all set


The different Sharepoint Web services make have use of CAML (Collaborative Application Markup Language).  CAML is an XML-based language that is used in Microsoft Windows SharePoint Services to define the fields and views used sites and lists. CAML is also used to define tables in the Windows SharePoint Services database during site provisioning.

Resources on CAML

  1. SDK - Within the SDK, there are is a good section on CAML.   Go to the index tab and search on CAML.
  2. How to use CAML here
  3. CAML query builder tool here

Writing code to consume the service

Once you have consumed the service, it is time to start coding against it.

In order to successfully call the QueryDocuments method you will need to know a few things.

  1. What site/sub-site you are trying to query data from
  2. What library (assuming here document library)
  3. What field you are using in your query.

Once you know the following, you are pretty much set.  Below is sample code that should help you connect and query data.  (BTW, this is NOT production code, but simple a dumping into one method for sake of this post)

Here are a few lines explained

EQUALS_QUERY_2PARAMS - This is the CAML query used to return data from the web service call.  This can be changed to fit your needs, see the CAML specs for more information about how to do this.

service.Credentails - This needs to be set to DefaultCredentials in order to work.

service.URL - Because the way that SharePoint stores data, you will need to set the URL at run time.  Sharepoint will only allow you to access the data from the given sub-site that your service is in.

service.QueryDocuments - This is the call into the web service to get the actual data.

foreach statement - When the service call returns, it returns a populated dataset object.  In order to get data out you will need to loop through and get each row.  There may be better ways, but this is simple and works.

There you have it, a simple straight forward way to use the SPServices.asmx service from Sharepoint.

Till next time,

kick it on
Posted 07-21-2007 9:30 AM by Derik Whittaker



Links (7/22/2007) « Steve Pietrek’s SharePoint Stuff wrote Links (7/22/2007) « Steve Pietrek’s SharePoint Stuff
on 07-22-2007 8:23 PM
John Hartley wrote re: Using Sharepoint's Web Services to QueryDocuments.
on 02-11-2008 12:46 PM


Thanks for your very thorough and comprehensive posting and code on Sharepoint development. It certainly greatly helps developers like me in law firms from the UK who are just dipping their toes into Sharepoint manipulation,  banging there head in frustration and also having to report back and explain reasons for progress or lack of progress  to Project Managers.

What I wanted to know however is using your code above do you need the Microsoft.Sharepoint.dll to get it work ?

The first time I read this, I didnt think it was necessary which is why I initially went ahead, but on the second time of reading I think you are saying that you will need it, its just deeply frustrating where it first puts it when your trying to add it as a reference ?

I ask this because at present  our new developer builds are not ready to go, and seeing as we are working on older xp clients which do not allow you to download Windows Sharepoint Services 3.0 let alone find the .dll locally, I am limited to adding the main servers Lists.asmx  web service as a reference and using that. This doesn't recognise SPServices as a class when compiling ? I cant also find this very quickly in google. (This may  be me I realise and I will continue to search on this)

Either way  I wanted to congratulate you on a fascinating and interesting site and a very interesting and successful CAML tool.


Derik Whittaker wrote re: Using Sharepoint's Web Services to QueryDocuments.
on 02-11-2008 1:33 PM


No, I am only using the webservices and DO NOT need the .dll's directly.  You only need these if you are using the API (which the web services to for you).

John Hartley wrote re: Using Sharepoint's Web Services to QueryDocuments.
on 02-12-2008 8:32 AM

Thanks for the prompt reply Derik.

Am a bit more tuned in today on the problem.

I do have an issue though - could you tell me whether SPServices.asmx and its method QueryDocuments() comes straight out of the box with MOSS ? Or from the sdk ? We seem to chiefly use Lists.asmx which doesnt contain the same method. I also dont have full access rights to the sharepoint server so cannot check if it is from the sdk.

Again much appreciated for all your help, and the links to the u2u site

Derik Whittaker wrote re: Using Sharepoint's Web Services to QueryDocuments.
on 02-12-2008 8:47 AM


Now that you mention it, I think this is a custom service we had via a 3rd party package.  Sorry about that.

You can get the list of all the available services here

You can also find a list of all the methods on the web, google them.

Hope this helps.

sanjoy wrote re: Using Sharepoint's Web Services to QueryDocuments.
on 04-09-2008 4:37 AM

hi i am new in sharepoint.

i am having some questions regarding the sharepoint and the web services.

1> When to call the provided web-service in  the Sharepoint?

2> What is return value of the web-services?

Means these only return the metadata of the document  or the Document file also.

3> I want to use Document managment system in my website and give the facilities to user like

a>Check in/ Check out

b>Search Document

c>Delete document

d>Give access to a particular user

Could u please help me out, i am extreamly new in sharepoint

Chris wrote re: Using Sharepoint's Web Services to QueryDocuments.
on 11-25-2008 6:34 PM

Like you, I need to be able to grab some data from Sharepoint and have not been able to find a decent web post, and I thought you had it!

But the SPServices.asmx web service is not part of WSS and not part of MOSS, but instead a custom 3rd party web service, right?  If correct, how do you grab some data from Sharepoint via a WSS web service?

youngmoony wrote Useful Links 058
on 03-04-2012 4:40 PM

Useful Links 058

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)