I am working on a project that receives a FileStream and it should receive it with a method that returns a MemoryStream.
How can I convert the MemoryStream to FileStream? I can't touch those codes and there lies the entire problem.
I am working on a project that receives a FileStream and it should receive it with a method that returns a MemoryStream.
How can I convert the MemoryStream to FileStream? I can't touch those codes and there lies the entire problem.
If I understand your question correctly, you have a method that returns a MemoryStream, and you need to pass that stream to a method that takes a FileStream. I've seen several instances where colleagues of mine have written methods with a FileStream parameter when the parameter type could have been Stream. This is an excellent example of why it's better to use the less-derived type for the parameter.
The only solution I can think of is to write the memory stream to a temporary file: create a file stream for the temporary file, copy the memory stream to the file stream, and then either set the position to zero or close the stream and open a new stream on the same file, to pass to the method.
If I have misunderstood your question, please clarify.
This has been discussed at Convert a Stream to a FileStream in C#