All-Star
16806 Points
2777 Posts
Microsoft
Aug 24, 2014 09:28 PM|Kevin Shen - MSFT|LINK
Hi saritapatil.888,
For your problem , I wrote a demo test it.
It worked very well in my computer.
I create a button in the page, when I click the button it will call the GetServerDate () method.
Below is my code:
<form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> </div> </form>
protected void Button1_Click(object sender, EventArgs e) { GetServerDate(); } [WebMethod] public static void GetServerDate() { HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=test.xlsx"); HttpContext.Current.Response.TransmitFile(HttpContext.Current.Server.MapPath("~/XmlDemo/tss.xlsx")); HttpContext.Current.Response.End(); }
I suggest that you can set a breakpoint on your GetServerDate() method, debug it and check if it can be hit and see if it has any error message.
if does ,please post here.
Best Regards,
Kevin Shen.
All-Star
16806 Points
2777 Posts
Microsoft
Re: excel file not download cause of Webmethod [System.Web.Services.WebMethod] public st...
Aug 24, 2014 09:28 PM|Kevin Shen - MSFT|LINK
Hi saritapatil.888,
For your problem , I wrote a demo test it.
It worked very well in my computer.
I create a button in the page, when I click the button it will call the GetServerDate () method.
Below is my code:
I suggest that you can set a breakpoint on your GetServerDate() method, debug it and check if it can be hit and see if it has any error message.
if does ,please post here.
Best Regards,
Kevin Shen.