Solved

# Save generated output to folder instead of displaying in browser

Posted on 2014-02-08
294 Views
Hi Experts

My code below takes the current html of a page and creates a PDF. I am struggling to find a way to save the PDF into a folder instead of showing it in the browser

Dim htmlToPdf = New HtmlToPdfConverter()
Dim pdfData = htmlToPdf.GeneratePdf(html)
Response.ContentType = "application/pdf"
Response.OutputStream.Write(pdfData, 0, pdfData.Length)
Response.[End]()

0
Question by:takwirirar
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 6
• 3

LVL 75

Expert Comment

ID: 39844239
Save it in a folder where:  on the server or on the client?
0

LVL 1

Author Comment

ID: 39844242
Apologies on the server
0

LVL 75

Accepted Solution

käµfm³d   👽 earned 500 total points
ID: 39844244
Replace lines 3 - 5 with:

System.IO.File.WriteAllBytes("path\to\folder", pdfData)  ' First parameter may need to change
'  to Server.MapPath("path\to\folder")
'  depending on which folder you are
'  referencing

0

LVL 1

Author Comment

ID: 39844259
Thank you it tries to do it then says

 System.Web.HttpException: A page can have only one server-side Form tag.


I tried it with

 Public Overrides Sub VerifyRenderingInServerForm(control As Control)
End Sub


and without but get the same error

I have placed the line as follows

System.IO.File.WriteAllBytes(Server.MapPath("~\PDF\test.pdf"), pdfData)

0

LVL 75

Expert Comment

ID: 39844260
That sounds like an issue in your markup file, not your code-behind file. Do you have two <form> tags in your HTML somewhere?
0

LVL 1

Author Comment

ID: 39844266
No I have just 1
Default.aspx
0

LVL 1

Author Comment

ID: 39844307
I have noticed that it creates the file which is brilliant news but its just the error that I need to get rid off.
0

LVL 1

Author Comment

ID: 39844324
I have also noticed that if I remove the only form tag and place the code in the form load, everything works fine however this renders the form useless as none of the controls work without the form tag.

This is how I am generating the html

  'Generate from current page
Dim renderedOutput As StringBuilder
Dim strWriter As StringWriter
Dim tWriter As HtmlTextWriter
Dim html As String

'create a HtmlTextWriter to use for rendering the page
renderedOutput = New StringBuilder
strWriter = New StringWriter(renderedOutput)
tWriter = New HtmlTextWriter(strWriter)
'render the page output
Page.RenderControl(tWriter)
html = renderedOutput.ToString


Maybe if I change that it'll work? Is there any other way to get the HTML of the current page?
0

LVL 1

Author Closing Comment

ID: 39894270
Thanks
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
###### Suggested Courses
Course of the Month9 days, 14 hours left to enroll