views:

97

answers:

1

These are 2 questions. The first one: I have an HttpHandler returning a zip file to download. I have this line of code:

context.Response.AppendHeader("content-disposition", "attachment; filename=myzipfile.zip");

The question is: should I declare the ContentType (application/zip) also ?

The second question is: I want to call this HttpHandler from a jQuery ajax call. I send parameters in json format. How should I declare the contentType of the ajax call?

Thanks for your time.

A: 

The question is: should I declare the ContentType (application/zip) also ?

Yes.

I want to call this HttpHandler from a jQuery ajax call

Calling a server side script that returns binary zip stream using AJAX makes little sense as you won't be able to manipulate the response.

Darin Dimitrov
Thanks for your answer. What do you suggest for the scenario I described?
opaera
You haven't described any scenario. You just asked two questions to which I gave an answer. If you want an user to be able to download a file create a simple link that points to your ashx handler. No need of AJAX: `<a href="/yourhandler.ashx?param1=value1">Download ZIP</a>`.
Darin Dimitrov
I explain you better what I want to do. HttpHandler returns different status codes in case of errors. I want to manage these ones and then I want to call the httphandler sending params in Post. I think I can't do this with a simple link. What do you suggest for doing this?
opaera
You could use a `<form action="/yourhandler.ashx" method="POST">` in this case.
Darin Dimitrov
I can't I think, I have my form in a masterpage. I'm trying with an ajax call (jQuery), my httphandler works fine but I can't get the file to download, the ajax call seems to throw an error. I should declare a dataType for the ajax call but what about a zip file? I really thank you for your time.
opaera