【问题标题】:How do I convert a FileContentResult to a FileStreamResult?如何将 FileContentResult 转换为 FileStreamResult?
【发布时间】:2015-03-05 20:51:17
【问题描述】:

我有一个从字节数组中获取的 FileContentResult,并希望将其转换为 FileStreamResult。这可能吗?如果是这样,怎么做?

【问题讨论】:

    标签: c# asp.net filecontentresult filestreamresult


    【解决方案1】:

    首先,我对 MVC 了解不多,但听起来您不应该需要这样做。如果你的代码依赖于FileStreamResult,看看你是否可以让它依赖于FileResult,这是FileStreamResultFileContentResult的基类。

    但除此之外,您始终可以使用:

    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.
    

    【讨论】:

    • 嘿,这对我回答的问题有用!感谢那。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    • 2010-09-08
    • 2013-09-21
    • 2011-05-14
    相关资源
    最近更新 更多