开发者

Can I edit the response object on Ajax call?

I have a link button on my page clicking on which, I download a file from some DMS system and then send the file af开发者_高级运维ter zipping it on server to the client using response.write.

But since the page is ajaxified, it throws an error.

Is possible to send a file to the client on a Ajax call?

I am using Telerik RadAjax.


Don't use Response.Write or Response.WriteFile to force file-download because that will simply not help in this context.

In order to do what you want, save the zipped file on disk and redirect the user to download-file. You can create a temp folder to hold the zipped files which you create on the fly and flush them every one hour or any such predefined time-interval. You need to call this from standard post-back driven non-ajaxed call. This will preserve the state.

Response.Redirect("path-file-to-download");
Response.End();


There is no reason to request the file with an AJAX callback, as downloading the file doesn't refresh the page and therefore the user doesn't lose the context, which is usually the reason why you would prefer AJAX callback.

According to your comments, there are 2 ways to overcome the problem :

  1. You can write into the response stream at the same time that you are downloading the file from the second server and therefore making the progress visible in the open/save dialog of the browser.
  2. You can temporarily store the file somewhere in the database / file system and send it with a second request made directly by the user.

The first one seems more reasonable to me as you don't have to deal with the intermediate storage.


You can send whatever data you like, you just have to be able to handle it in your JavaScript.

There isn't a great deal that JavaScript could do with a zipped file (unless you fancy finding, or writing, a zip decompression library in JavaScript).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜