2

I have requirement like open any document in web browser. I am using WEBAPI for getting document details(byte Format).I am able to download .but I want to open in browser using IFRAME in ASP.NET MVC.

user3824027
  • 440
  • 3
  • 10

2 Answers2

1

As to the base requirement, this is really straight-forward, and it sounds like you're mostly there. The only problem is you can't simply set an iframe to some blob of data. Think of the iframe as another browser window; it just happens to be embedded within a web page. You have to set the iframe to a URL that it should load. As a result, all you need is some action in your MVC project that consumes your Web Api and returns the document as a response. Then you just set your iframe to load the URL that routes to that action.

However, there's a huge caveat: a web browser can't just load a random document. Web browsers parse HTML. That's it. Anything else needs a plugin. Some browsers, like Chrome, include support for some file types, like PDFs, out of the box. Others need plugins manually installed. It's generally a safe bet that PDF will supported for inline viewing in most browsers due to its prevalence online. (If the user's browser doesn't support it out of the box, there's a high likelihood that the user would have installed a PDF viewer plugin at some point to add support). If you're talking about a Word document or such, you're mostly out of luck, though.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
1
<embed style="width:100%; height:1300px; " src="~/PDF/Arma3Lau.pdf" type="application/pdf" />

Thats the way to display pdf-files