Rank: Member Groups: Member
Joined: 7/11/2013 Posts: 11
|
I have several forms that are converted to PDF on submission using ASPXToPDF and after the final form is submitted I need to print the forms and then delete the forms from the directory. My issue is that I think the directory is deleted before the conversion finishes for that form so then it can't save the form because the directory doesn't exist. Is there some way to wait until the conversion is complete before code after is executed? Below is my code for the conversion and then the print function which deletes the folder with the pdf files after they have been printed.
Code: C#
protected void btnSubmit_Click(object sender, EventArgs e)
{
btnSubmit.Visible = false;
ASPXToPDF.RenderAsPDF(false);
ASPXToPDF.AfterRender += new EventHandler(ASPXToPDF_AfterRender);
printPDF();
}
protected void ASPXToPDF_AfterRender(object sender, EventArgs e)
{
HtmlToPdfResult htmlResult = (HtmlToPdfResult)ASPXToPDF.Result;
htmlResult.PdfDocument.Save("C:\\Folder\\Document.pdf");
}
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
No. The conversion ALWAYS happens at the LAST because it has to capture whatever changes your code made to your page. So it would be wrong to make it happen before your other code is executed.
Thanks!
|
Rank: Member Groups: Member
Joined: 7/11/2013 Posts: 11
|
In that case, how would you recommend printing after the final form is converted?
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
Your code as to creating the PDF file is correct. As to why the folders is gone by the time the PDF file is created, that is related to your application logic and we would not know. All we can suggest is whatever you were doing before the conversion (for example, the code that deleted the directory), you need to restructure your code so that it does not happen before the conversion, for example, you may want to put that into a different background thread to do that. Obviously the exact detail is more about your application so we are not in a position to offer tech support on that.
Thanks!
|