excel file not download cause of Webmethod [System.Web.Services.WebMethod] public static void GetServerDate(string xmldata) { RRS feed

  • Question

  • User1610357552 posted
            public static void GetServerDate(string xmldata)
    HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=MyFile.xlsx");


    Friday, August 22, 2014 5:45 AM


  • 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">
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
     protected void Button1_Click(object sender, EventArgs e)
            public static void GetServerDate()
                HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=test.xlsx");

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 24, 2014 9:28 PM