This is a migrated thread and some comments may be shown as answers.

Excel output to Response Stream

2 Answers 152 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 28 Feb 2013, 04:14 PM
I get a strange error when i try to output an excel report book to a response stream. This code was working perfectly before cant figure out why telerik is behaving strangely. We are using Telerik reporting 4.0.10.310.  
What is wrong... my intention is the excel file must download to the client on click of a button.
Here when i click on the save and open the file from the local drive the xls is perfect.
but when i click on open .... it downloads a copy of the aspx page where it says the format is different or the file is corrupted.
This is my code
I found if i remove the multiview and the view the same exact code works perfectly. I have another form where this kind of set up works(multiview-view-updatepanel). I dont understand the difference.
What is wrong?


Page has a buttion inside Multiview->view->updatepanel

<asp:MultiView ID="mvwReports" runat="server">

<asp:View ID="vwTotalCostOfOwnership" runat="server">

                                <div id="divExport" runat="server" class="aright">

                                     <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional" RenderMode="Inline">

                                        <ContentTemplate>

                                            <asp:ImageButton ID="imgBtnExcel" runat="server" CausesValidation="false" ToolTip="Excel"

                                                Visible="true" AlternateText="Excel" Enabled="true" ImageUrl="~/App_Themes/WebBlue/images/excel_icon.gif"

                                                OnClick="imgBtnExcel_OnClick" />

                                        </ContentTemplate>

                                        <Triggers>

                                            <asp:PostBackTrigger ControlID="imgBtnExcel" />

                                        </Triggers>

                                    </asp:UpdatePanel></div>

                                    </asp:View>

                                    </asp:MultiView>

Code behind

protected void Page_Load(object sender, EventArgs e)

        {

            mvwReports.ActiveViewIndex = 0;

            

        }

        protected void imgBtnExcel_OnClick(object sender, EventArgs e)

        {

            Response.Clear();

            Response.ContentType = "application/vnd.ms-excel";

            Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);//(HttpCacheability.Private);

            Response.Expires = -1;

            Response.Buffer = true;

            Response.AddHeader("Content-Disposition", string.Format("{0};FileName=\"{1}\"",

                                "attachment","test" + ".xls"));

            Response.TransmitFile("e:\\temp\\excel\\test.xls");

            HttpContext.Current.ApplicationInstance.CompleteRequest();

        }

2 Answers, 1 is accepted

Sort by
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 04 Mar 2013, 01:04 PM
Check this out: 
http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx
0
David
Top achievements
Rank 1
answered on 04 Mar 2013, 03:51 PM
Thanks...
In my case for what so ever reason...
Internet Options->Advanced->Reset worked...
I had problem with only one report in the application and the others worked just fine so i was not suspecting IE for a long time.
I use IE 9
Thanks
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Hadib Ahmabi
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or