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.
-
hi check the [link](http://stackoverflow.com/questions/1244788/embed-vs-object) – Shailesh Singh Feb 01 '16 at 12:12
-
Hi Shalish.I am getting response as binary data form DataBase.it is dynamic.how can get the URL of this binary data? – user3824027 Feb 01 '16 at 12:26
-
`var urlCreator = window.URL || window.webkitURL; var Url = urlCreator.createObjectURL(binary_data);` – Shailesh Singh Feb 01 '16 at 12:34
-
is this client side code ? – user3824027 Feb 01 '16 at 12:43
2 Answers
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.

- 232,153
- 36
- 385
- 444
-
Thanks Chris, how can make binary data of any document to URL.So that i can give that URL to IFRAME. – user3824027 Feb 02 '16 at 05:49
-
Return `File` with byte array rather than the traditional `View` from your action. – Chris Pratt Feb 02 '16 at 14:45
<embed style="width:100%; height:1300px; " src="~/PDF/Arma3Lau.pdf" type="application/pdf" />
Thats the way to display pdf-files

- 86
- 10