Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm using Sharepoint 2007 and unfortunately don't have any ways to server site scripting, no C# or PowerShell.

  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\\");
myDate.setDate(myDate.getDate()-365);       
var FSo = new Enumerator(f.Files);               
for(i=0;!FSo.atEnd();FSo.moveNext())`

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

Updated code:

I've just did what you wrote and put the code on the server like below but nothing is being display. How do I check response xml ?

Thanks

<script language="javascript" type="text/javascript">

var soapEnv = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
    <listName>Library</listName>
   <query>
   <Query>
<Where>
  <Lt>
     <FieldRef Name='Modified' />
     <Value Type='DateTime'>
        <Today  Offset = '-15' />
     </Value>
  </Lt>
</Where>
</Query></query>       
</GetListItems>
</soap:Body>";


$.ajax({
url: "/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: ProcessListItems,
contentType: "text/xml; charset=\"utf-8\""
}); 


function ProcessListItems(xData, status) {
//to count items
var itemCount=$(xData.responseXML).find("z\\:row").length;
//to iterate through items
$(xData.responseXML).find("z\\:row").each(function()
{
alert(itemCount);
}


</script>
share|improve this question
add comment

1 Answer

You can use lists.asmx web service to achieve the task from client side using ajax call, navigate to http:// yoursitename/_vti_bin/lists.asmx and find GetListItems, or you can directly navigate to http:// yoursitename/_vti_bin/lists.asmx?op=GetListItems , check the soap header format and construct your ajax, you can easily get file attributes, count of files. And you can always use CAML query to filter the data as you wish. Let me know if you need any further help.


Sample code

first construct the soap envelope

var soapEnv = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
    <listName>Your Doc Library Name</listName>
    <query><Query>Your caml query goes here</Query></query>        
</GetListItems>
</soap:Body>";

then ajax call -

$.ajax({
url: "/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: ProcessListItems,
contentType: "text/xml; charset=\"utf-8\""
});   

and in the ProcessListItems you can do whatever you wish -

function ProcessListItems(xData, status) {
//to count items
var itemCount=$(xData.responseXML).find("z\\:row").length;
//to iterate through items
$(xData.responseXML).find("z\\:row").each(function(){//your logic here});}

have a look at raw response xml to know how you can retrieve one specific xml attribute, in general if you wish to retrieve say TECH field of a record inside .each function it should be like - $(this).attr('ows_TECH') but please have a look at response xml to be sure

and for CAML part if you need help, you can check this


Your CAML will look like

<Query>
<Where>
  <Lt>
     <FieldRef Name='Modified' />
     <Value Type='DateTime'>
        <Today  Offset = '-365' />
     </Value>
  </Lt>
</Where>
</Query>

But please do check for correctness, I have not tested it

share|improve this answer
    
Diptarag, Many thanks for your tip. However I would need more details as I never used GetListItem. Any simple example or something similar which I could start with would be great. Thanks Again ! –  user13069 Nov 19 '12 at 6:32
    
okay i am trying to add some sample code here, i assume you can handle the jQuery part, the code is not tested i am writing on the flow just to give you some idea –  Diptarag Nov 19 '12 at 6:45
    
Much appreciated ! I will deferentially check it out and try to figure out myself. If not I'll get back with questions. For jQuery - Yes I can handle that part. Thanks! –  user13069 Nov 19 '12 at 6:51
    
added code, please have a look, try to construct yourself, if you face difficulties, please revert back –  Diptarag Nov 19 '12 at 7:00
    
Thanks for your time. I'm already looking into CALM tutorial. Just one clarification as I don't know soap at all. Do I put this code into the same html as ajax and JS part or it needs different file? Also any files that I need to import to use sopa? Z\\:row seems to have problems with Chrome (at least google says so). I'll try this $(xData.responseXML).find("[nodeName=z:row]").each(function(){ instead. Shouldn't "var soapEnd" in soap part be "var soapEnv" to match ajax call ?I'll get back later on the day. Thanka again ! –  user13069 Nov 19 '12 at 8:06
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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