4

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

4

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
        });
3

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

  • 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
1

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

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.