Files created from app using Graph API always shown as created by "Sharepoint App"

Viewed 197

My app is creating a file (DriveItem) using Graph API. It's using GraphServiceClient from Microsoft.Graph nuget and gets access token with ClientSecretCredential.

Here's the part when the file gets created:

public async Task CreateFile(string driveId, string folderId, string filename, byte[] content)
{
    var driveItem = new DriveItem()
    {
        Name = filename,
        File = new Microsoft.Graph.File()
        {
            MimeType = "application/pdf"
        },
        AdditionalData = new Dictionary<string, object>()
        {
            { "@microsoft.graph.conflictBehavior", "rename" }
        }
    };

    var response = await _client.Drives[driveId].Items[folderId].Children.Request().AddAsync(driveItem);
    await _client.Drives[driveId].Items[response.Id].Content.Request().PutAsync<DriveItem>(new MemoryStream(content));
}

The problem is that the file that's created has the following createdBy identity set:

"createdBy": {
    "application": {
        "id": "[app-id]",
        "displayName": "[app-display-name]"
    },
    "user": {
        "displayName": "SharePoint App"
    }
}

and the name shown in CreatedBy column when viewing files list in Teams is "SharePoint App" instead of my app's display name. When I try to manually set values for CreatedBy property and overwrite user's displayName it simply get ignored.

Am I missing something or is this by design and files created by apps ale always shown as created by "SharePoint App"?

2 Answers

According to the documentation createdBy property is read-only.

It will contain identity of the user, device, or application which created the item.

SharePoint App is an inbuilt account used in apps and local to SharePoint only.

It is used when the customer sets up, one App, and provides that App a high level permission to run on the SharePoint Site.

Drive item properties

SharePoint App is an inbuilt account used in apps and local to SharePoint only. There is no user associated with the action, in lieu of an actual user identity we show the system-defined SharePoint App as the user. We confirmed it from internally also.

Related