San*_*Lev 1 c# asp.net filestreamresult filecontentresult
我有一个从字节数组中获取的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.
Run Code Online (Sandbox Code Playgroud)