User1918509225 posted
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.