This project has moved and is read-only. For the latest updates, please go here.

How to get files count from particular library?

Nov 18, 2012 at 11:03 PM


I'm using Sharepoint 2007 and unfortunately don't have any ways to server site scripting.

1. Is there any way to get total number of files in a given Library using SPServices ?

2. It would be great if I could also access files attributes. So for instance I have attribute called 'FileType' use to store technical type of the document. Lets say 'TECH1', 'TECH2', 'TECHN' I would want to get count of files with only FileType =  'TECH2'.

3. Also attribute  'Modified'. Any chance to loop through files in a library and count all files older than for instance today - 365 days ?

Maybe it can be done  easier than SPServices ? I'm not that much web programmer :(

I was playing around with    myObject = new ActiveXObject("Scripting.FileSystemObject");
              f = myObject.GetFolder("\\\\mysite\\sites\\space\\Library\\");
              var FSo = new Enumerator(f.Files);               

But this turned out to be dead end working from my local but not on the server ...



Nov 19, 2012 at 1:05 PM

The SPServices "GetListItems" operation will get you what you're looking for.  It will return a set of documents from the selected library and you can optionally filter the returned set using a CAML query (you can include both of your filtering elements in one query).  The returned XML stream will include a node called "rs:data" with an "ItemCount" attribute.  The documentation for the GetListItems operation in this site is quite clear and includes an example.  For the CAML Query parameters, you can learn more about that at MSDN. To select the "rs:data ItemCount" attribute, you include that in the operation's "completefunc:" argument.  You can use a jQuery selector such as $(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount"). The jQuery reference documentation is here.