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

3 Answers 3


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

            url: "site.url/_api/web/lists/getByTitle('LibraryName')/items?$top=1000&$select=FileLeafRef",
            type: "GET",
                           "accept": "application/json;odata=verbose"
            success: filesuccess,
            error: error

try this:

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

function errorListHandler(){

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

  • Including the name of file, URL, Size and more... Commented Nov 21, 2013 at 16:24
  • If help mark with answer. Tanks! Commented Nov 21, 2013 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


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 and acknowledge you have read our privacy policy.

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