Cannot access a closed Stream while creating a downloadable text file in ASP MVC 3

前端 未结 4 742
臣服心动
臣服心动 2021-02-06 23:06

Im trying to prompt a downloadable text file (.txt), but I get this error:

Cannot access a closed Stream.

I have looked at simular q

4条回答
  •  抹茶落季
    2021-02-06 23:46

    You have to set the position of the memorystream to 0 before using it in your FileStreamResult, otherwise it will be read from current position (IE the end of the stream).

    stream.Position = 0;
    return File(stream, "text/plain", name);
    

    Just had the same thing.

    I know this thread is ancient, just hoping to aid others having the same issue.

提交回复
热议问题