Link to home
Start Free TrialLog in
Avatar of bubu600b2
bubu600b2Flag for United States of America

asked on

How to fetch a document with a particular version status and custom property in Sharepoint 2007 Web Services

Is there a straightforward way to fetch a document from a sharepoint repository using the Web Services based on the following conditions:

The status of the file must be 'Draft'.
The KeyName should be 'abcd'. (Key name is a custom property for each document on Sharepoint)

Currently I am using Lists.asmx to GetListCollection() and the GetListItem() and parse all the data, but this is very cumbersome and I hope for all that Microsoft provides, there is a more straightforward way to get this. I was looking at the Query() function in spsearch.asmx. Is there a way I can write a <QueryPacket> that could fetch this file more easily?
Avatar of arduk
arduk

using the GetListItems web service (http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems(v=office.12).aspx), you can either
1. Create a view that displays the correct filtered list, and then retrieve the contents of that view
or
2. Create a CAML query which you would pass in as the QueryOptions tag, which defines your filter

Hope this helps!
Avatar of bubu600b2

ASKER

Thanks Arduk. For both options 1 and 2 we need the administrator of the site to create a view that contains the documents I assume - so that the GetListItems service can be called.
Let me enunciate on the previous comment. I see this structure in the links on the left hand side of the Sharepoint website:


Documents
AbcSheets
 
Lists
AbcTasks
 
Discussions  
 
Sites  
 
People and Groups  
 
When I run the GetListItems service with the following code:

javascript:document.getElementById('selector2').className='selectedAttach'; editCS('873663', false, false);

(nameAttr.Value has the GUID of the 'AbcSheets' list)
I get this result:






There are no rows in the list though I see several documents when I select  the 'AbcSheets' link under the 'Documents' menu. Is there a problem with the way the Site has been setup or am I doing something wrong in calling the service.
XElement query = XElement.Parse("<Query></Query>");
                        XElement viewFields = XElement.Parse("<ViewFields></ViewFields>");
                        XElement queryOptions = XElement.Parse("<QueryOptions><IncludeMandatoryColumns>TRUE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc></QueryOptions>");

                        XElement xListItems = client.GetListItems(
                            nameAttr.Value,
                            null,
                            query,
                            viewFields,
                            "10",
                            queryOptions,
                            null);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of arduk
arduk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Arduk... thanks for the link and the help. I found the solution, sorry for the silence btw.

Turns out I was accessing the service using the wrong account. (Duh!) But now I got the service working. Thanks a lot!