Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: jQuery
Hi,
 
I did a ajax call using jquery to a handler. In the handler's response I write the context type and save a pdf file. Now in the jquery I have to open the pdf file. I used jquery file download plugin. But it doesn't work for me. Plz help me, to complete this task.
 
JQuery:
 
 function CallHandler() {
                 $.ajax({
             url: "iss_report.ashx",
             contentType: "application/json; charset=utf-8",
             success: OnComplete,
             error: OnFail
         });
         return false;
     }
     function OnComplete(result) {
            $.fileDownload(result);
     }
     function OnFail(result) {
         alert('Request failed');
     }
In handler:
public class iss_report : IHttpHandler {
    public iss_report()
    {
    }
 
    public void ProcessRequest (HttpContext context) {
  Workbook wb= new Workbook();
 
        context.Response.SetCookie(new HttpCookie("fileDownload", "true") { Path = "/" });
        context.Response.ContentType = "application/pdf";
        invoicebook.Save(context.Response, "mybook.pdf", ContentDisposition.Attachment, new PdfSaveOptions());
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
Posted 14-Nov-12 1:33am
Edited 14-Nov-12 17:03pm
v3
Comments
Marcus Kramer at 14-Nov-12 8:43am
   
Why did you tag your question C++. C++ is a whole different ball of wax from C#.
Sergey Alexandrovich Kryukov at 14-Nov-12 23:06pm
   
Tag: ASP.NET, C#, jQuery
--SA
n.podbielski at 15-Nov-12 3:46am
   
Do not work? Are there some errors?
Sam Jenifa at 15-Nov-12 4:39am
   
Thanks for your reply.
Ya, it doesn't work.File download error occurs. How to resolve it?? plz help me.
n.podbielski at 15-Nov-12 5:24am
   
What error ? Can you be more specific?
Sam Jenifa at 15-Nov-12 6:40am
   
I used a plugin by referring this link(http://johnculviner.com/post/2012/03/22/Ajax-like-feature-rich-file-downloads-with-jQuery-File-Download.aspx).
In the plugin they used iframe. The file to be placed in the hidden iframe, because of that it shows the file download dialog box. The last code which i post, has some error. I directly passed the response get from the handler.
Now I changed the code like this.
JQuery:
function CallHandler() {
$.ajax({
url: "iss_report.ashx",
contentType: "application/json; charset=utf-8",
success: OnComplete,
error: OnFail
});
return false;
}
function OnComplete(result) {
$.fileDownload('report/report.PDF');
}
function OnFail(result) {
alert('Request failed');
}
Handler:
public class iss_report : IHttpHandler {
public iss_report()
{
}

public void ProcessRequest (HttpContext context) {
Workbook wb= new Workbook();
string file = ConfigurationManager.AppSettings["pdfreportlocation"].ToString() + "\\report.PDF";
context.Response.SetCookie(new HttpCookie("fileDownload", "true") { Path = "/" });

invoicebook.Save(file);
}

public bool IsReusable {
get {
return false;
}
}
Every steps are working fine.But I didn't get file download dialog box or any error message. In the status bar a message blink for a second that start downloading... But nothing happened.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 540
1 OriginalGriff 300
2 CPallini 290
3 ChauhanAjay 124
4 George Jonsson 120
0 OriginalGriff 6,474
1 Sergey Alexandrovich Kryukov 6,190
2 CPallini 5,180
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100