Home > Enterprise >  How to Convert from MemoryStream to FileStream to pass to MS Graph?
How to Convert from MemoryStream to FileStream to pass to MS Graph?

Time:12-03

I have a MemoryStream object that contains the contents of a file. I would like to convert it from a MemoryStream to a FileStream in order to pass it to MS Graph's enter image description here

Yes, a FileStream is a Stream but a MemoryStream is also a Stream and is a "readable, seekable stream" like the docs say is required; it means you can just pass the MemoryStream you have for the uploadStream parameter.

Perhaps make sure you've Seek'd it to Position 0 before you pass it.. If you've just finished writing into a Memorystream, it's Positioned at the end. If you then pass it to something that will start reading from it, that thing usually reads nothing (because the stream is at the end) - seek the stream back to the start/where you want the upload to begin because you should assume that the thing you give it to will not seek it before reading from it

  •  Tags:  
  • c#
  • Related