Search code examples
c#microsoft-graph-apionedrive

DriveItem.CreatedBy.Device property is null for files in OneDrive


I am using Microsoft Graph Client .Net SDK to search for files in my OneDrive. I am searching for all .docx files under the root folder:

IDriveItemSearchCollectionPage searchResults = await graphClient
    .Me
    .Drive
    .Root
    .Search(query)
    .Request()
    .GetAsync();

The issue is that I need the Device info that created the file but in the Microsoft Graph response the DriveItem.CreatedBy.Device property is always null.

How can I retrieve the Device information associated with the CreatedBy or LastUpdatedBy properties of the DriveItem

Could this be due to the fact that I have not registered any device to AAD? Do the devices need to be registered to AAD for Microsoft Graph to retrieve the information of the device that created the file?


Solution

  • The createdBy property returns the microsoft.graph.identity object associated with the file's creation. Which type of identity is returned depends on how the file was created:

    • If a signed-in user uploaded the file, it will return the user identity.
    • If an application without a signed-in user (i.e. a daemon service) created the file, it will return the application identity.
    • If a device without a signed-in user created the file (i.e. a Surface Hub), it will return the device identity.