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

What is the best way to get a list of all the file names in a sharepoint document library with javascript?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Apparently there's a property called FileLeafRef, and I could query the library like so...

$.ajax({
            url: "site.url/_api/web/lists/getByTitle('LibraryName')/items?$top=1000&$select=FileLeafRef",
            type: "GET",
            headers:
                       {
                           "accept": "application/json;odata=verbose"
                       },
            success: filesuccess,
            error: error
        });
share|improve this answer

try this:

$.ajax({
        url: "site/_api/web/GetFolderByServerRelativeUrl('Documents')/Files",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function(data){
            //console.log(data);
            for(var i = 0; i<data.d.results.length; i++){
                var result data.d.result[i];
            }               
        },
        error: errorListHandler
    });

function errorListHandler(){
    alert('Error!');
}

In var result you have information about the file[i] of the array of files

share|improve this answer
    
Including the name of file, URL, Size and more... –  Diego Hillesheim Nov 21 '13 at 16:24
    
If help mark with answer. Tanks! –  Diego Hillesheim Nov 21 '13 at 17:58

You can make use of CAML query to fetch the values as below,

var caml = "<View><ViewFields><FieldRef Name='Title'/></ViewFields></View>

Or you can make use of

$().SPServices

Have a look at the below link,

Get List items using Jquery

share|improve this answer

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.