Click here to Skip to main content
15,125,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
PLease help me, I have an aspx page which has to display some files of types docx and xlsx... I am trying to use iframe with google docs viewer, but an error is thrown:No preview available. Below is my code in my aspx page:

ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DisplayFile.aspx.cs" Inherits="Pages_DisplayFile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
    body {
     margin: 0px;
    }
    .doc {
       border: 0; width: 100%; height: 100%;
    }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <iframe class="doc" src="https://docs.google.com/gview?url=http://localhost:2342/Project-Test-Temp/Uploaded/Save.docx"&embedded=true"></iframe>
     </div>
    </form>
</body>
</html>


Here is a working example:

Edit fiddle - JSFiddle[^]

How can I resolve this issue and display my word and excel file normally? I appreciate your helps

What I have tried:

I have tried this:

HTML
<iframe class="doc" src="../UploadedImages/Save.docx"></iframe>


But it is downloading file !!
Posted
Updated 6-Mar-17 7:38am
v4

1 solution

Actually, the X-Frame-Options is not turn on for docs.google.com domain. SO it, should work, my guess is it could be the JavaScript error somewhere in the code?

This is because the google.com domain has X-Frame-Options turn on.

"X-Frame-Options tells the browser whether you want to allow your site to be framed or not. By preventing a browser from framing your site you can defend against attacks like clickjacking."

Scan results for google.com[^]
   
v2
Comments
H.AL 7-Mar-17 7:55am
   
Thank you for your answer, but no errors... I solved by publishing my doc file on a public server, the issue is that docs.google.com cannot read a file from local file server.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900