【发布时间】:2015-03-05 20:51:17
【问题描述】:
我有一个从字节数组中获取的 FileContentResult,并希望将其转换为 FileStreamResult。这可能吗?如果是这样,怎么做?
【问题讨论】:
标签: c# asp.net filecontentresult filestreamresult
我有一个从字节数组中获取的 FileContentResult,并希望将其转换为 FileStreamResult。这可能吗?如果是这样,怎么做?
【问题讨论】:
标签: c# asp.net filecontentresult filestreamresult
首先,我对 MVC 了解不多,但听起来您不应该需要这样做。如果你的代码依赖于FileStreamResult,看看你是否可以让它依赖于FileResult,这是FileStreamResult和FileContentResult的基类。
但除此之外,您始终可以使用:
var streamResult = new FileStreamResult(new MemoryStream(contentResult.FileContents),
contentResult.ContentType)
streamResult.FileDownloadName = contentResult.FileDownloadName;
// You could use an object initializer instead of a separate statement, of course.
【讨论】: