Is it possible to get byte[] from FileResult?
Asked Answered
K

1

8

Is it possible to get byte[] from FileResult in C#?

Koester answered 13/11, 2014 at 17:49 Comment(2)
If you need the file bytes why not just read the file directly? FileResult is the wrong type to use.Unsuccessful
@Unsuccessful Well I don't have access to that functionality. I have access to get FileResult only.Koester
I
13

FileResult is an abstract class so that won't be the underlying instance type - assuming the correct overload is used then you should be able to cast it to a FileContentResult

if (result is FileContentResult data)
{
    var content = data.FileContents;
}
Ihram answered 13/11, 2014 at 18:11 Comment(3)
FWIW for the sake of code clarity, i think an explicit cast would be preferred in this situation as you'd prefer an InvalidCastException over a NullReferenceException.Dermatophyte
@YuvalItzchakov I'd like think neither would be preferred :)Ihram
*FileContents insteadProclivity

© 2022 - 2024 — McMap. All rights reserved.