exclude folder from results in SharePoint rest api

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I am using rest api to get the list of all files inside a document library



However this also brings the list of all folders



Is there a way to filter out the folders and bring only the files using rest api?



$.ajax(
url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('Document Library Name')/items?$top=1000&$select=Title,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText",
headers: "Accept": "application/json; odata=verbose" ,
cache: false,
success: function (data)
//some code
,
error: function (xhr)
console.log(xhr);

);









share|improve this question



























    up vote
    1
    down vote

    favorite












    I am using rest api to get the list of all files inside a document library



    However this also brings the list of all folders



    Is there a way to filter out the folders and bring only the files using rest api?



    $.ajax(
    url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('Document Library Name')/items?$top=1000&$select=Title,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText",
    headers: "Accept": "application/json; odata=verbose" ,
    cache: false,
    success: function (data)
    //some code
    ,
    error: function (xhr)
    console.log(xhr);

    );









    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am using rest api to get the list of all files inside a document library



      However this also brings the list of all folders



      Is there a way to filter out the folders and bring only the files using rest api?



      $.ajax(
      url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('Document Library Name')/items?$top=1000&$select=Title,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText",
      headers: "Accept": "application/json; odata=verbose" ,
      cache: false,
      success: function (data)
      //some code
      ,
      error: function (xhr)
      console.log(xhr);

      );









      share|improve this question













      I am using rest api to get the list of all files inside a document library



      However this also brings the list of all folders



      Is there a way to filter out the folders and bring only the files using rest api?



      $.ajax(
      url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('Document Library Name')/items?$top=1000&$select=Title,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText",
      headers: "Accept": "application/json; odata=verbose" ,
      cache: false,
      success: function (data)
      //some code
      ,
      error: function (xhr)
      console.log(xhr);

      );






      rest sharepoint-rest-api






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Vignesh Subramanian

      1,48032053




      1,48032053




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote













          you can use this snip of code to filter your results and exclude Folders



          var g; 
          $.ajax(
          url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists/GetByTitle('Training Material')/Items",
          type: 'GET',
          dataType: "json",
          headers:
          "Accept": "application/json;odata=verbose",
          "content-type": "application/json; odata=verbose",
          "X-RequestDigest": $("#__REQUESTDIGEST").val()
          ,
          success: function (data)
          for (var i = 0; i < data.d.results.length; i++)
          if (data.d.results[i].FileSystemObjectType != 1)


          ,
          error: function (request, error)
          console.log(JSON.stringify(request));

          );


          The above code will return all the items of document library including folders. So, to exclude folders, we can use FileSystemObjectType property to determind whether the current item is folder or file. For more information on FileSystemObjectType, visit This Link






          share|improve this answer



























            up vote
            1
            down vote













            You have to change the REST URL and point to the document library.
            data.Files property will contain only the files and data.Folders will contain the folders.



            var RestUrl= _spPageContextInfo.webAbsoluteUrl+ "/_api/Web/GetFolderByServerRelativeUrl('/Shared%20Documents')?$expand=Folders,Files"; //document library name

            $.getJSON(RestUrl,function(data,status,xhr)

            if(data.Files.length > 0)

            var results = data.Files;

            );


            The above code is tested and works fine.






            share|improve this answer





























              up vote
              0
              down vote













              A few more options actually available:




              items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=FSObjType eq 0




              FSObjType (display name Item Type) is a built-in field, values are based on this enumeration



              OR




              items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=startswith(ContentTypeId, '0x0101')




              Later approach uses content type and filters out only items which are File-based content type (0x0101)






              share|improve this answer




















                Your Answer







                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "232"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                 

                draft saved


                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsharepoint.stackexchange.com%2fquestions%2f250411%2fexclude-folder-from-results-in-sharepoint-rest-api%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                1
                down vote













                you can use this snip of code to filter your results and exclude Folders



                var g; 
                $.ajax(
                url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists/GetByTitle('Training Material')/Items",
                type: 'GET',
                dataType: "json",
                headers:
                "Accept": "application/json;odata=verbose",
                "content-type": "application/json; odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
                ,
                success: function (data)
                for (var i = 0; i < data.d.results.length; i++)
                if (data.d.results[i].FileSystemObjectType != 1)


                ,
                error: function (request, error)
                console.log(JSON.stringify(request));

                );


                The above code will return all the items of document library including folders. So, to exclude folders, we can use FileSystemObjectType property to determind whether the current item is folder or file. For more information on FileSystemObjectType, visit This Link






                share|improve this answer
























                  up vote
                  1
                  down vote













                  you can use this snip of code to filter your results and exclude Folders



                  var g; 
                  $.ajax(
                  url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists/GetByTitle('Training Material')/Items",
                  type: 'GET',
                  dataType: "json",
                  headers:
                  "Accept": "application/json;odata=verbose",
                  "content-type": "application/json; odata=verbose",
                  "X-RequestDigest": $("#__REQUESTDIGEST").val()
                  ,
                  success: function (data)
                  for (var i = 0; i < data.d.results.length; i++)
                  if (data.d.results[i].FileSystemObjectType != 1)


                  ,
                  error: function (request, error)
                  console.log(JSON.stringify(request));

                  );


                  The above code will return all the items of document library including folders. So, to exclude folders, we can use FileSystemObjectType property to determind whether the current item is folder or file. For more information on FileSystemObjectType, visit This Link






                  share|improve this answer






















                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    you can use this snip of code to filter your results and exclude Folders



                    var g; 
                    $.ajax(
                    url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists/GetByTitle('Training Material')/Items",
                    type: 'GET',
                    dataType: "json",
                    headers:
                    "Accept": "application/json;odata=verbose",
                    "content-type": "application/json; odata=verbose",
                    "X-RequestDigest": $("#__REQUESTDIGEST").val()
                    ,
                    success: function (data)
                    for (var i = 0; i < data.d.results.length; i++)
                    if (data.d.results[i].FileSystemObjectType != 1)


                    ,
                    error: function (request, error)
                    console.log(JSON.stringify(request));

                    );


                    The above code will return all the items of document library including folders. So, to exclude folders, we can use FileSystemObjectType property to determind whether the current item is folder or file. For more information on FileSystemObjectType, visit This Link






                    share|improve this answer












                    you can use this snip of code to filter your results and exclude Folders



                    var g; 
                    $.ajax(
                    url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists/GetByTitle('Training Material')/Items",
                    type: 'GET',
                    dataType: "json",
                    headers:
                    "Accept": "application/json;odata=verbose",
                    "content-type": "application/json; odata=verbose",
                    "X-RequestDigest": $("#__REQUESTDIGEST").val()
                    ,
                    success: function (data)
                    for (var i = 0; i < data.d.results.length; i++)
                    if (data.d.results[i].FileSystemObjectType != 1)


                    ,
                    error: function (request, error)
                    console.log(JSON.stringify(request));

                    );


                    The above code will return all the items of document library including folders. So, to exclude folders, we can use FileSystemObjectType property to determind whether the current item is folder or file. For more information on FileSystemObjectType, visit This Link







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 1 hour ago









                    Melad Francis

                    8041614




                    8041614






















                        up vote
                        1
                        down vote













                        You have to change the REST URL and point to the document library.
                        data.Files property will contain only the files and data.Folders will contain the folders.



                        var RestUrl= _spPageContextInfo.webAbsoluteUrl+ "/_api/Web/GetFolderByServerRelativeUrl('/Shared%20Documents')?$expand=Folders,Files"; //document library name

                        $.getJSON(RestUrl,function(data,status,xhr)

                        if(data.Files.length > 0)

                        var results = data.Files;

                        );


                        The above code is tested and works fine.






                        share|improve this answer


























                          up vote
                          1
                          down vote













                          You have to change the REST URL and point to the document library.
                          data.Files property will contain only the files and data.Folders will contain the folders.



                          var RestUrl= _spPageContextInfo.webAbsoluteUrl+ "/_api/Web/GetFolderByServerRelativeUrl('/Shared%20Documents')?$expand=Folders,Files"; //document library name

                          $.getJSON(RestUrl,function(data,status,xhr)

                          if(data.Files.length > 0)

                          var results = data.Files;

                          );


                          The above code is tested and works fine.






                          share|improve this answer
























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote









                            You have to change the REST URL and point to the document library.
                            data.Files property will contain only the files and data.Folders will contain the folders.



                            var RestUrl= _spPageContextInfo.webAbsoluteUrl+ "/_api/Web/GetFolderByServerRelativeUrl('/Shared%20Documents')?$expand=Folders,Files"; //document library name

                            $.getJSON(RestUrl,function(data,status,xhr)

                            if(data.Files.length > 0)

                            var results = data.Files;

                            );


                            The above code is tested and works fine.






                            share|improve this answer














                            You have to change the REST URL and point to the document library.
                            data.Files property will contain only the files and data.Folders will contain the folders.



                            var RestUrl= _spPageContextInfo.webAbsoluteUrl+ "/_api/Web/GetFolderByServerRelativeUrl('/Shared%20Documents')?$expand=Folders,Files"; //document library name

                            $.getJSON(RestUrl,function(data,status,xhr)

                            if(data.Files.length > 0)

                            var results = data.Files;

                            );


                            The above code is tested and works fine.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 1 hour ago

























                            answered 1 hour ago









                            Sohail Shaikh

                            1917




                            1917




















                                up vote
                                0
                                down vote













                                A few more options actually available:




                                items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=FSObjType eq 0




                                FSObjType (display name Item Type) is a built-in field, values are based on this enumeration



                                OR




                                items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=startswith(ContentTypeId, '0x0101')




                                Later approach uses content type and filters out only items which are File-based content type (0x0101)






                                share|improve this answer
























                                  up vote
                                  0
                                  down vote













                                  A few more options actually available:




                                  items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=FSObjType eq 0




                                  FSObjType (display name Item Type) is a built-in field, values are based on this enumeration



                                  OR




                                  items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=startswith(ContentTypeId, '0x0101')




                                  Later approach uses content type and filters out only items which are File-based content type (0x0101)






                                  share|improve this answer






















                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    A few more options actually available:




                                    items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=FSObjType eq 0




                                    FSObjType (display name Item Type) is a built-in field, values are based on this enumeration



                                    OR




                                    items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=startswith(ContentTypeId, '0x0101')




                                    Later approach uses content type and filters out only items which are File-based content type (0x0101)






                                    share|improve this answer












                                    A few more options actually available:




                                    items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=FSObjType eq 0




                                    FSObjType (display name Item Type) is a built-in field, values are based on this enumeration



                                    OR




                                    items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=startswith(ContentTypeId, '0x0101')




                                    Later approach uses content type and filters out only items which are File-based content type (0x0101)







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 18 mins ago









                                    Sergei Sergeev

                                    8,97352240




                                    8,97352240



























                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsharepoint.stackexchange.com%2fquestions%2f250411%2fexclude-folder-from-results-in-sharepoint-rest-api%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        Comments

                                        Popular posts from this blog

                                        What does second last employer means? [closed]

                                        List of Gilmore Girls characters

                                        One-line joke