0

I'm able to grab the files, but haven't been successful excluding more than one file name ending with vsdx or avi.

I need to exclude more than one file type.

Any suggestions?

<script type="text/javascript">
$.ajax({
url: "https://gumdropsgc.sharepoint.com/sites/Training/_api/web/GetFolderByServerRelativeUrl('Production_Library/communication management')/files?$select=LinkingURL,Name&$orderby=LinkingURL$filter=not endswith(Name,’vsdx’)",
type: "GET",
headers: {"Accept": "application/json;odata=verbose"},
cache:false,                
success: function(data){
        console.log(data);
        var html = "<table border='0'>";
        $(data.d.results).each(function(){
            html = html + "<a href='" + this.LinkingUrl + "' target='_blank' >" + this.Name + "</a><br/>" ;
        });
        html += "</table>";
        $("#listResult2").html(html)
    }
});
</script>
0
$(data.d.results).each(function(){
var fileExt = this.Name.split('.').pop();
if (fileExt != "vsdx" && fileExt != "avi")
{
 html = html + "<a href='" + this.LinkingUrl + "' target='_blank' >" + this.Name + "</a><br/>" ;
}
});
1

To rephrase your question, you would like to filter files by file extensions. If so, then i would recommend to consider these options:

Aboutendswith function

According to OData query operators supported in the SharePoint REST service endsWith function is not supported

Using substringof function

Since endsWith function is not supported, here is an alternative solution that allows to filter files by extension.

The example demonstrates how to exclude files those names contains .xslx or .docx

/_api/web/GetFolderByServerRelativeUrl('Documents')/files?$filter=not substringof('.docx',Name) and not substringof('.xslx',Name)

Using CAML query

The following example demonstrates how to filter list items by extension using CAML query:

function getListItems(webUrl,listTitle,folderUrl, viewXml) 
{
    var url = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems"; 
    var queryPayload = {  
               'query' : {
                      '__metadata': { 'type': 'SP.CamlQuery' }, 
                      'ViewXml' : viewXml,
                      'FolderServerRelativeUrl': folderUrl
               }
    };

    return $.ajax({
           url: url,
           method: "POST",
           data: JSON.stringify(queryPayload),
           headers: {
              "X-RequestDigest": $("#__REQUESTDIGEST").val(),
              "Accept": "application/json; odata=verbose",
              "content-type": "application/json; odata=verbose"
           }
     });
}

Usage

Example that returns list items under Guides folder from Documents library and excludes .docx & .xslx file types:

var query = '<View>' +
              '<Query>' + 
                 '<Where>' +
                    '<And><Neq><FieldRef Name="File_x0020_Type" /><Value Type="text">docx</Value></Neq><Neq><FieldRef Name="File_x0020_Type" /><Value Type="text">html</Value></Neq></And>' +
                 '</Where>' +
               '</Query>' +
             '</View>';
getListItems(_spPageContextInfo.webAbsoluteUrl,'Documents','/Documents/Guides',query)
.done(function(data)
{
     var items = data.d.results;
     for(var i = 0; i < items.length;i++) {
         console.log(items[i].Title);
     }    
})
.fail(
function(error){
    console.log(JSON.stringify(error));
});

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.