Reputation: 313
I have updated on of our projects to .Net 7, which required me to update our version of Microsoft Graph API to version 5.38. For the most part, things are working fine, with the exception of getting files from SharePoint. I am using the method below to get the file content:
await _graphServiceClient.Drives[docFolderId].Items[file.Id].Content.GetAsync();
This does seem to get the file content, however, when you look at the properties of the object, you will see that a number of the properties fail, such as the basic one of Length. The error I get is below:
((System.Net.Http.HttpBaseStream)fileContent).Length = '((System.Net.Http.HttpBaseStream)fileContent).Length' threw an exception of type 'System.NotSupportedException'
This doesn't make sense to me and I can't help but think it is a bug. But, I wanted to ask the community to see if anyone else has encountered this and found a way around it?
Upvotes: 0
Views: 126
Reputation: 20625
The stream returned by the method
var fileContent = await _graphServiceClient.Drives[docFolderId].Items[file.Id].Content.GetAsync();
is not buffered by default, so you can't read the length of the stream.
Try to copy the stream into a memory stream and read the length of that stream
using var ms = new MemoryStream();
await fileContent.CopyToAsync(ms);
var length = ms.Length;
Upvotes: 1