SearchDriveItems
Searches for OneDrive and SharePoint files by keyword using the Microsoft Search API. Returns one row per matching file with metadata and a search excerpt.
Stored Procedure Specific Information
Select
This stored procedure uses the Microsoft Search API to perform full-text search across OneDrive and SharePoint file content. The Files.ReadWrite.All permission configured for the connector is sufficient to use this procedure.
The Keyword parameter supports KQL (Keyword Query Language) syntax for advanced filtering. For example, you can scope results to a specific site using
path:"https://tenant.sharepoint.com/sites/mysite", or filter by file type using
filetype:docx.
The Id and DriveId output columns can be used to retrieve the full file record from the Files table.
Sample statements:
EXEC SearchDriveItems Keyword = 'quarterly report' EXEC SearchDriveItems Keyword = 'budget filetype:xlsx', MaxRows = '25' EXEC SearchDriveItems Keyword = 'project plan path:"https://tenant.sharepoint.com/sites/mysite"'
Input
| Name | Type | Required | Description |
| Keyword | String | True | The keyword or phrase to search for across file names and content in OneDrive and SharePoint. The search is full-text and is not equivalent to SQL LIKE pattern matching. Supports KQL syntax for advanced filtering, such as filetype:docx or path: |
| MaxRows | String | False | Maximum number of results to return across all pages. Set to 0 or leave unset to return all available results. For example, set to 50 to limit results to 50 files. |
Result Set Columns
| Name | Type | Description |
| Id | String | Unique identifier of the drive item. Use this value to retrieve the full file record from the Files table. |
| Name | String | File or folder name, including the extension. |
| WebUrl | String | Direct URL to open the file in a browser. |
| Size | Long | File size in bytes. |
| DriveId | String | Identifier of the drive that contains the file. Use together with Id to construct drive-scoped queries against the Files table. |
| SiteId | String | Identifier of the SharePoint site that contains the file. |
| ParentId | String | Identifier of the parent folder. |
| ParentPath | String | Path of the parent folder within the drive. |
| MimeType | String | MIME type of the file, such as application/vnd.openxmlformats-officedocument.wordprocessingml.document. Empty for folders. |
| CreatedDateTime | Datetime | Timestamp indicating when the file was created. |
| LastModifiedDateTime | Datetime | Timestamp indicating when the file was last modified. |
| CreatedByDisplayName | String | Display name of the user who created the file. |
| LastModifiedByDisplayName | String | Display name of the user who last modified the file. |
| Rank | Int | Relevance rank of the search result. Lower values indicate higher relevance. |
| Summary | String | Search excerpt showing the portion of the file content that matched the query. Matching terms are wrapped in c0 tags. |