I've written a custom httphandler for DocX files, and I'm trying to have the files be displayed through an iframe.
Here's my controller:
public ActionResult LoadDOC(string path)
{
var fsSource = new FileStream(path, FileMode.Open, FileAccess.Read);
return new FileStreamResult(fsSource, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
{
FileDownloadName = "newfile.docx"
};
}
}
The file name needs to be changed so that the httphandler can pick it up. The files reside on the fileserver without extensions (they're renamed to a guid). For example:
"\\\\fileservername\\Documents\\811943a3-56f7-42cb-8450-1b8319a426b4\\633d9f3e-df99-408e-b59c-ec8efa4fa41f"
I can't change the way the files reside on the server, I'll have to add the extension through code.
When the above is executed in an iframe, the file is immediately downloaded. PDF files and text files render properly however.
Here is the custom httphandler:
<add name="DOCXhandler" path="*.docx" verb="GET" type="MyProject.Handlers.DocxHandler, MyProject" preCondition="integratedMode" />
How can I go about either changing the file stream extension using this approach, or another approach to perhaps achieve the desired result of the file displayed in an iframe?
Is it possible to just change the handler by content type?
Edit: Question for clarity;
- Is it possible to make an http handler work by content type, instead of file extension?
- How can I make sure the filestreamresult uses my custom httphandler for .docx files when displaying in the iframe?
- Am I going about this the correct way, or am I missing something?