Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends,
I have a excel file in server. And i have a button in a web form. When user clicks that button it will download that excel file to client machine.

I need that code urgently.

I am using this below code

C#
Response.ContentType = "image/jpeg";
        Response.AppendHeader("Content-Disposition", "attachment; filename=Image.xml");
        Response.TransmitFile(Server.MapPath("XML/Image.xml"));
        Response.End();


It is working fine but when i keeping it within Update Panel not working. Any suggestion.
Posted
Updated 17-Aug-12 3:27am
v3
Comments
[no name] 17-Aug-12 9:08am    
www.vworker.com
I.explore.code 17-Aug-12 9:24am    
this is not a code shop mate! the only reason i have suggested a solution is because you have shown your own efforts first unlike some people who say "i want do xyz. give me codes". And hence I have struck out that line in your question.
RaviRanjanKr 17-Aug-12 9:31am    
Always wrap your code in pre tag.

XML
<div>
      <asp:ScriptManager ID="ScriptManager1" runat="server" >
      </asp:ScriptManager>
      <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
     <ContentTemplate>
      <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
      </ContentTemplate>
      <Triggers>
      <asp:PostBackTrigger  ControlID="Button1"  />
      </Triggers>

       </asp:UpdatePanel>
  </div>
 
Share this answer
 
try this on the button click event:

VB
Dim dlScript As String = String.Format("window.open('{0}');", "/XML/image.xml")
            ScriptManager.RegisterStartupScript(Page, GetType(String), "fileDownloadScript", dlScript, True)


it should work...it uses ScriptManager to register script to show the download dialog
 
Share this answer
 
Thanks kamalakanta nayak,
I used your suggestion for using Trigger
XML
<Triggers>
      <asp:PostBackTrigger  ControlID="Button1"  />
      </Triggers>


and it works fine..
 
Share this answer
 

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