Short version:
I have a third-party MVC Extension that returns the FileResult. I would like to be able to process the file before returning it to the client. How can I do that?
If you’re interested in boring details, read below:
I’m using Devexpress XtraReports for reporting purposes. The problem is that it’s PDF Export is terrible, but RTF one works great. I would like to create action&result filter that would trick DevExpress into generating rtf instead of pdf (done) and convert the rtf to pdf using some other third-party library. The only problem is that I need to obtain rtf file from FileResult and return my own FileResult with the converted content.
//EDIT:
The code right now looks as follows:
public virtual ActionResult ReportExport(TParameters parameters)
{
return DevExpress.Web.Mvc.ReportViewerExtension.ExportTo(this.GetReport(parameters));
}
You said you are using a third-party MVC extension that returns a
FileResultand you want to access the file details that are wrapped inside the result.If you see the
FileResult, it is an abstract class and I just know there are three built-in implementations are available in MVC (I don’t aware about others):FileContentResult,FileStreamResultandFilePathResult.All these classes provide public properties to access the details of the file. For ex. the
FileContentResultcontains a public property calledFileContentsthat returns the content of a file as a byte array.The third-party extension can return any
FileResultimplementation of the built-in types or badly(if you can’t access those type) their own types as well. You can check the returnedFileResultinstance’s type and cast it accordingly to access the file details.If you want make the things reusable you can implement a custom file result that takes the
FileResultreturned by the extension in the constructor and override theWriteFilemethod.