2

I need to list all the files located in one document library that match a specific naming convention: The documents to retrieve are all in the form 'Report xxxx-xx-xx'.

I have to use the GetListItems web service.

Is there a way to collect all these documents in one call? How to write the 'where' section in the query part? Can I use some regex in this?

Thanks

4

You can send a CAML query to the GetListItems service. CAML doesn't support regex, but it does have operators for BeginsWith and Contains.

<Query>
   <Where>
      <BeginsWith>
         <FieldRef Name="Title" />
         <Value Type="Text">Report</Value>
      </BeginsWith>
   </Where>
</Query>

To do full regex style matching and get exactly what you want, you would then have to filter the result set on the client side using Javascript's regex.

4
  • I don't really understand what CAML is really but to my perspective, it's only a problem of what SharePoint can interpret in the value. --- Example: <Value Type="Text">Report (\d\d\d\d-\d\d-\d\d)</Value> Sep 27 '12 at 6:05
  • It interprets what you put in. You could build up a more complicated expression with Ands and Ors to make sure it contains a - and digits 0-9 if that helps you narrow it down further, but it doesn't support regex, it doesn't even support a concept of "NotContains".
    – lgaud
    Sep 27 '12 at 13:07
  • For BeginsWith, Contains, it will ultimately convert it to an SQL "LIKE" expression, but it will mess with any wildcards you put in. So Contains [0-9]-[0-9] gets changed to LIKE N'%[[]0-9]-[[]0-9]%'
    – lgaud
    Sep 27 '12 at 13:32
  • Thanks @lgaud It's clear Sep 28 '12 at 7:58
1

Perhaps you could add a Calculated Column on your document library, that performs a string manipulation and/or test operation on your title text, and returns eg something that can then easily be picked up in your where clause?

This might help limit the result set at the server side...

=IF(LEFT([TitleColumn],7)="Report ", if(ISNUMBER(DATEVALUE(RIGHT([TitleColumn],10))), "TRUE", "FALSE"), "FALSE")

Refer to Microsoft's Calculated Field Formulas for what's available in calculated columns.

4
  • A good idea, I can re-use somewhere else but this is too complicated in this case. if I have to build a calculated column for each different request... Sep 28 '12 at 8:00
  • @AlbanSoupper You stated The documents to retrieve are all in the form 'Report xxxx-xx-xx' This will identify all of those documents in that format (I've assumed xxxx-xx-xx is a datestamp). And then a single where clause to filter on just the result of this column. Or have I misunderstood?
    – Sepster
    Sep 28 '12 at 16:10
  • It's correct :) Oct 1 '12 at 8:43
  • @AlbanSoupper so since you need to list all the files located in one document library, you only need to add one column.
    – Sepster
    Oct 3 '12 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.