Search code examples
c#asp.net-mvcsharepointcsomsharepoint-search

CSOM SharePoint Search API filter files only


Using CSOM Search API is there a way to filter for only files? Something similar to the following ListItem filter would be ideal:

ListItem.FileSystemObjectType.Equals(FileSystemObjectType.File)

Ex use case:

if (item.FileSystemObjectType.Equals(FileSystemObjectType.File))
{
    // do stuff
}

The only thing similar I have found in documentation would be using the filetype Keyword Query Language (KQL) filter:

filetype:docx

I'd like to avoid using that, however, as setting all the possible valid file types feels like a sloppy solution IMO. Thanks for any feedback!


Solution

  • You should use the below filter to limit results for documents only:

    IsDocument:1