Is it possible to get byte[]
from FileResult
in C#?
Asked
Active
Viewed 8,158 times
8

NoWar
- 36,338
- 80
- 323
- 498
-
If you need the file bytes why not just read the file directly? `FileResult` is the wrong type to use. – asawyer Nov 13 '14 at 17:59
-
@asawyer Well I don't have access to that functionality. I have access to get FileResult only. – NoWar Nov 13 '14 at 18:07
1 Answers
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;
}
-
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`. – Yuval Itzchakov Nov 13 '14 at 21:31
-
-
4