In My Web application,
I want download the file from ajax call.
reference:
Call HTTPhandler from jQuery, Pass data and retrieve in JSON format[
^]
here i am unable to download file, see my code below
In Handler.ashx file
public void ProcessRequest(HttpContext context)
{
string PPTOutputPath = context.Request.QueryString["DownLoadFileName"];
PPTOutputPath = PPTOutputPath.Replace(",", "\\");
FileInfo PPTFileNewfile = new FileInfo(PPTOutputPath);
long sz = PPTFileNewfile.Length;
context.Response.ClearContent();
context.Response.ContentType = MimeType(Path.GetExtension(PPTOutputPath));
context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", System.IO.Path.GetFileName(PPTOutputPath)));
context.Response.AddHeader("Content-Length", sz.ToString("F0"));
context.Response.TransmitFile(PPTOutputPath);
context.Response.Flush();
context.Response.End();
}
My ajax call
function CallHandler(PPTOutputPath) {
$.ajax({
type: 'POST',
url: "MyHandler.ashx?DownLoadFileName=" + PPTOutputPath,
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{'imageData': '" + PPTOutputPath + "'}",
responseType: "json",
success: OnComplete,
error: OnFail
});
return false;
}
function OnComplete(result) {
alert('Ajax success');
}
function OnFail(result) {
alert('Ajax failed');
}
i am getting ajax failed message and file not down loading