Click here to Skip to main content
14,733,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am able to create pdf document with client side call(jquery ajax) in codebehind but
unable to download. i am stroing data table data in view state and reteriving form there
when client side call fires?
is there way to download it
Posted
Comments
ZurdoDev 8-Jan-15 9:57am
   
If you are creating a physical copy on the disk you can redirect the user to the file (if it's in IIS's folder structure.) Or, you can read it in binary and send that to the response stream.
chandubbbb 8-Jan-15 10:08am
   
it throwing exceptions response is not available

you can't do that as you are making ajax call to server and for downloading something from server you have to make complete postback.
So you can do like this.

in your ajax call make or save your pdf file on the server like YourApplicationName/PDF/sample.pdf.
and return this path from your ajax call.Now your file is on the server and you know the path but the thing that is remaining is download this file.For this you can use complete function and hidden iframe complete:function(){
//your code
var iframe = document.createElement("iframe");
               iframe.src = "GenerateFile.aspx?page=ViewDrawing";
               iframe.style.display = "none";
               document.body.appendChild(iframe);


}
And in GenerateFile.aspx page load event you can write your pdf downloadable code.
   
I agree on Solution 1. But have to add that you'll need to set the following header in you GenerateFile.aspx. Otherwise some browsers will just diplay the pdf in the hidden iframe.

context.Response.AddHeader("Content-Disposition", "attachment;filename=my.pdf");
   

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900