Share via

c# Graph Api > 5..0.15 Content.GetAsync() not working any more

Uwe Schöneis 10 Reputation points
2023-08-11T09:45:01.1066667+00:00
// https://learn.microsoft.com/en-us/answers/questions/1025116/how-to-download-a-mail-graph-api-c?orderby=oldest
Stream mimeContentStream = await _graphClient.Users[{someUseriD}].Messages[{aMessageId}].Content.GetAsync();
string mailFile = "anyFileName.eml";
using (var fileStream = System.IO.File.Create(mailFile))               
{
	mimeContentStream.Seek(0, SeekOrigin.Begin);
	mimeContentStream.CopyTo(fileStream);
};

On updating the graph API from 5.0.15 to any higher version mimeContentStream is invalid.
Is this by design? If the request is no longer supported there should be at least an error, exception, or whatever.
Returning an invalid stream is NOT an option as it breaks the compatibility whith the existing code, based on Graph API 5.0.x.
Developer technologies | .NET | Other
Microsoft Security | Microsoft Graph
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


2 answers

Sort by: Most helpful
  1. jcq 6 Reputation points
    2023-09-26T15:20:09.11+00:00

    Here i have solution with 5.28:

    https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2144

    And this worked for me, my problem was with reading the stream (old method doesn't work anymore).

    var res = await graphServiceClient.Me.Messages["{message-id}"].Content.GetAsync();
    var data = new StreamReader(res).ReadToEnd();
    

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Uwe Schöneis 0 Reputation points
    2023-09-27T05:11:24.74+00:00

    Thanks jcq for digging into it! It works including V5.0.15. Hopefully MS will provide working sample code as they change the graph version ....

    Was this answer helpful?

    0 comments No comments

Your answer

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