c# - FileStreamResult and custom httphandler -


i've written custom httphandler docx files, , i'm trying have files displayed through iframe.

here's 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 changed httphandler can pick up. files reside on fileserver without extensions (they're renamed guid). example:

"\\\\fileservername\\documents\\811943a3-56f7-42cb-8450-1b8319a426b4\\633d9f3e-df99-408e-b59c-ec8efa4fa41f" 

i can't change way files reside on server, i'll have add extension through code.

when above executed in iframe, file downloaded. pdf files , text files render however.

here custom httphandler:

      <add name="docxhandler" path="*.docx" verb="get" type="myproject.handlers.docxhandler, myproject" precondition="integratedmode" /> 

how can go either changing file stream extension using approach, or approach perhaps achieve desired result of file displayed in iframe?

is possible change handler content type?

edit: question clarity;

  • is possible make http handler work content type, instead of file extension?
  • how can make sure filestreamresult uses custom httphandler .docx files when displaying in iframe?
  • am going correct way, or missing something?

consider adding ".docx" extension rendered url file , removing loaddoc action (i.e. cheap hack - path = path.replace(".docx", ""), prefer using methods path class manipulation).

side note: exposing server side file path bad idea security point of view.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

mysql - Pass value between different pages (form) with PHP -