0

I have a generic handler (.ashx) which is used to download an excel file. When I try to call it using the code below:

HttpWebRequest request = WebRequest.Create("ExcelDownload.ashx?id=123") as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;

the file is not downloaded.But,I am able to debug the handler code when the request is made.

But when the handler is used in the anchor tags,I am able to download the file.

<a href="ExcelDownload.ashx?id=123">Excel Download</a>

Any idea why the first option is not working?

Additional Comments: In the handler,I am using the below code which works fine with anchor tag. I am not doing any thing with the response object returned by the request.

context.Response.Clear();
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.Buffer = true;
byte[] buffer = memoryStream.ToArray();
context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", faWorkbookFileName));
context.Response.BinaryWrite(buffer);
context.Response.End();
jigsmshah
  • 165
  • 1
  • 4
  • 13

0 Answers0