Click here to Skip to main content
15,897,518 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionasp.net Pin
manoja medaramitla4-Jun-12 0:38
manoja medaramitla4-Jun-12 0:38 
AnswerRe: asp.net Pin
Rahul Rajat Singh4-Jun-12 1:02
professionalRahul Rajat Singh4-Jun-12 1:02 
AnswerRe: asp.net Pin
taha bahraminezhad Jooneghani4-Jun-12 9:52
taha bahraminezhad Jooneghani4-Jun-12 9:52 
AnswerRe: asp.net Pin
vvashishta4-Jun-12 22:13
vvashishta4-Jun-12 22:13 
Generalasp.net and c# Pin
sathik174-Jun-12 0:34
sathik174-Jun-12 0:34 
AnswerRe: asp.net and c# Pin
Rahul Rajat Singh4-Jun-12 1:04
professionalRahul Rajat Singh4-Jun-12 1:04 
GeneralRe: asp.net and c# Pin
Pankaj Nikam4-Jun-12 19:27
professionalPankaj Nikam4-Jun-12 19:27 
QuestionDisplay Excel File in .aspx Page Pin
paas1-Jun-12 4:53
paas1-Jun-12 4:53 
Hello,

I am trying to display an Excel file in a .aspx page that is opened from the page load event of another .aspx page via a window.open. The HTML of the .aspx page that will display the Excel is as follows...

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ExcelViewer.aspx.cs" Inherits="ExcelViewer"%>

<!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>Excel Viewer</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>


The PageLoad event of the code behind the .aspx page that will display the Excel file includes the following code:

      FileInfo fi = new FileInfo(sFilePath);  // sFilePath is path to Excel file...

      Response.Clear();
      Response.ClearHeaders();
      Response.ClearContent();
      Response.ContentType = sMIME;  // sMIME stores the mime type
      Response.AddHeader("Content-Disposition", "inline; filename=" + fi.Name);

       Response.WriteFile(sFilePath);
       Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
       File.Delete(sFilePath);


What I am finding is that the first time I try to open the Excel file with this code, I get the 'Internet Explorer cannot display the web page...Diagnose connections problems' error page. Then if I try to view the page shortly thereafter the Excel file comes up in the page just fine. Then if I try to view the page a 3rd time I get the error page again...etc. So every other time the viewing is succeeding.

Does anyone have any thoughts as to why this is only succeeding in viewing the Excel file every other time?

Edit: I have found that if my Content-Disposition is set to 'attachment', after receiving the 'Open' or 'Save' prompt and selecting 'Open' the file does open correctly every time in Excel. I would still prefer to use a disposition of 'inline' so the user does not have to be prompted each time a file is to be viewed.

Thank You.

modified 1-Jun-12 12:45pm.

AnswerRe: Display Excel File in .aspx Page Pin
Ravi Sant3-Jun-12 18:29
Ravi Sant3-Jun-12 18:29 
QuestionShow MS Lync presence in aspx web page Pin
meetprabhum1-Jun-12 3:32
meetprabhum1-Jun-12 3:32 
QuestionASP.Net Logout issue Pin
berba1-Jun-12 2:47
berba1-Jun-12 2:47 
AnswerRe: ASP.Net Logout issue Pin
keyur satyadev2-Jun-12 1:10
keyur satyadev2-Jun-12 1:10 
AnswerRe: ASP.Net Logout issue Pin
taha bahraminezhad Jooneghani3-Jun-12 2:19
taha bahraminezhad Jooneghani3-Jun-12 2:19 
AnswerRe: ASP.Net Logout issue Pin
thatraja4-Jun-12 17:13
professionalthatraja4-Jun-12 17:13 
AnswerRe: ASP.Net Logout issue Pin
august_star4-Jun-12 21:28
august_star4-Jun-12 21:28 
Question2010 web form problem Pin
sc steinhayse31-May-12 11:22
sc steinhayse31-May-12 11:22 
AnswerRe: 2010 web form problem Pin
R. Giskard Reventlov31-May-12 15:20
R. Giskard Reventlov31-May-12 15:20 
AnswerRe: 2010 web form problem Pin
taha bahraminezhad Jooneghani3-Jun-12 2:48
taha bahraminezhad Jooneghani3-Jun-12 2:48 
Questioncalling a function from a hyperlink Pin
wiins31-May-12 8:08
wiins31-May-12 8:08 
AnswerRe: calling a function from a hyperlink Pin
jkirkerx31-May-12 13:30
professionaljkirkerx31-May-12 13:30 
GeneralRe: calling a function from a hyperlink Pin
wiins31-May-12 22:15
wiins31-May-12 22:15 
GeneralRe: calling a function from a hyperlink Pin
jkirkerx1-Jun-12 6:57
professionaljkirkerx1-Jun-12 6:57 
GeneralRe: calling a function from a hyperlink Pin
wiins8-Jun-12 4:46
wiins8-Jun-12 4:46 
GeneralRe: calling a function from a hyperlink Pin
jkirkerx8-Jun-12 10:53
professionaljkirkerx8-Jun-12 10:53 
Question'cmbGender' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value Pin
mudunurusv30-May-12 23:36
mudunurusv30-May-12 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.