在上传的文件中包含描述

Include Description in Uploaded File

我正在使用 Graph API,使用 Graph API 中的示例代码,我可以将文件上传到 OneDrive

GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var stream = "The contents of the file goes here."

await graphClient.Me.Drive.Items["{item-id}"]
    .Request()
    .PutAsync(stream);

问题是,我想将 Description 包含到上传的文件中。 我不知道这是否可行,但找不到相关信息。

这取决于OneDrive personalOneDrive for Business/SharePoint document librarydrive type被利用。

来自driveItem resource type page

description String Provides a user-visible description of the item. Read-write. Only on OneDrive Personal

对于 OneDrive Personal,driveItem.Description 属性 可以这样更新:

//upload a file
var driveItem = await graphClient.Me.Drive.Items[itemId]
    .Content
    .Request()
    .PutAsync<DriveItem>(stream);


//update driveItem
var updateItem = new DriveItem { Description = "File uploaded" };
await graphClient.Me.Drive.Items[driveItem.Id].Request().UpdateAsync(updateItem);