|
Rank: Newbie Groups: Member
Joined: 12/22/2015 Posts: 2
|
I have the following code to copy an aspx page
protected void ASPXToPDF1_AfterRender(object sender, EventArgs e) { HtmlToPdfResult result = HtmlToPdf.Result; result.PdfDocument.Save(MapPath("~\\Output\\") + TextBox9.Text + DateTime.Now.ToString("yyyyMMddhhmm") + ".pdf");
TopBtn.Visible = true; BtmBtn.Visible = true; } protected void BtnSave_Click(object sender, EventArgs e) { TopBtn.Visible = false; BtmBtn.Visible = false; ASPXToPDF1.RenderAsPDF(false); ASPXToPDF1.AfterRender += new EventHandler(ASPXToPDF1_AfterRender); }
If I replace ASPXToPDF1.RenderAsPDF(false); with ASPXToPDF1.RenderAsPDF("savefileas"); it save the file successfully on the client (in downloads folder).
I get the following error below. Please assist me with this issue.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 346: { Line 347: //do nothing Line 348: result.PdfDocument.Save(MapPath("~\\Output\\") + TextBox9.Text + DateTime.Now.ToString("yyyyMMddhhmm") + ".pdf"); Line 349: Line 350: }
Source File: C:\inetpub\wwwroot\Supreme\Signoff53.aspx.cs Line: 348
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] System.Web.UI.Page.MapPath(String virtualPath) +62 Signoff53.ASPXToPDF1_AfterRender(Object sender, EventArgs e) in C:\inetpub\wwwroot\Supreme\Signoff53.aspx.cs:348 EO.Web.ASPXToPDF.a(String A_0, Stream A_1) +304 EO.Internal.a9m.a(Chunk[] A_0) +83 Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.ArteryFilter.Close() +39 System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr) +700 System.Web.HttpResponse.FilterOutput() +117 System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +61 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +91
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1038.0
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
You can try to call MapPath inside your BtnSave_Click, save the result in a member variable and then use that member variable inside your ASPXToPDF1_AfterRender.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 12/22/2015 Posts: 2
|
I have the functionality working. A file is saved on the server side as I need it. At the same time I get a screen full of characters. If I reload the aspx page or select back, it displays correctly. The file is saved correctly in the right folder. How can ensure the correct screen is displayed. Can someone please assist with this issue.
protected void ASPXToPDF1_AfterRender(object sender, EventArgs e) { HtmlToPdfResult result = (HtmlToPdfResult)HtmlToPdf.Result; PdfDocument doc = result.PdfDocument; doc.Save(mappath.Value); //mappath.Value is saved in javascript and has the filename to save
TopBtn.Visible = true; BtmBtn.Visible = true; }
protected void BtnSave_Click(object sender, EventArgs e) {
TopBtn.Visible = false; BtmBtn.Visible = false; ASPXToPDF1.RenderAsPDF(false); ASPXToPDF1.AfterRender += new EventHandler(ASPXToPDF1_AfterRender); }
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, Your code is correct except that the following code in AfterRender has no effect: TopBtn.Visible = true; BtmBtn.Visible = true; You should remove those. If after that you continue to have problem, please try to isolate the problem into a separate test project and send us the test project. See here for instructions: http://www.essentialobjects.com/forum/test_project.aspxThanks!
|
|