Creating a ChatMessageAttachment From New DriveItem

TestDev1 0 Reputation points
2024-02-27T14:51:01.8033333+00:00

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.

Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,187 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.