Creating a ChatMessageAttachment From New DriveItem
I have asked this question here but haven't gotten a follow up response, so I'm reposting here as I would really like a solution.
Using C#, I've followed the guide to Upload large file to OneDrive and can successfully create the file in my OneDrive. I am the signed in user, using delegated permissions, obtaining an auth token via microsoftTeams.authentication.getAuthToken
and provided to the OnBehalfOfCredential
to initialize the GraphServiceClient.
After the DriveItem
is created, I use the logic in Send a message with a file attachment to share that newly created file with another user in a 1:1 Teams chat.
The issue is that other user does not have permissions to access the file once it is placed in the chat.
I've tried using the following code:
var linkRequestBody = new CreateLinkPostRequestBody
{
Type = "edit",
Scope = "organization",
};
var result = await graphClient.Drives[myDrive.Id].Items[di.Id].CreateLink.PostAsync(linkRequestBody);
The above code creates the sharing link, but that link it not able to be shared through a ChatMessageAttachment
because the link doesn't end with a document name and extension, which it must to match the name property or a runtime error is thrown when using Messages.PostAsync
.
What is the process to create a new DriveItem
, and share it with another user in Microsoft Teams chat programmatically using C#?
Thanks for any help.