I have an IEnumerable<string>
, which is "streamed" per yield
statements from a method. Now I want to convert this enumerable to a Stream
to use it as streamed result. Any ideas how I can do this?
What I finally want to do is to return the Stream
as FileStreamResult
from an ASP.NET controller action. This result should be streamed as download to the client.
What I do NOT want to do is to write the whole content of the IEnumerable
to the stream before I return the result. This would eliminate the whole sense of the streaming concept.
I think you can use it in this first convert your string to byte array and use memory stram afterwards
You have to create your ActionResult class to achieve lazy evaluation. You have create mix of
ContentResult
anFileStreamResult
classes to achieve behaviour like FileStreamResult with ability to set result encoding. Good starting point isFileResult
abstract class: