473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Save aspx output to a file on the server

In my web application there is an interactive report. Then there need
to be a printable version a pdf. So I found this java tool csstoxslfo
and the java fop tool from apache that will take my xhtml and css and
convert it to pdf.

Problem 1)
I designed the aspx page to produce the xhtml as output. So how do I
save that rendered page to a file on the server? I think it involves
overriding the Render method. I wrote some code which appears below
that I don't know if it will work. Anybody done this before and have
code examples?

Problem 2)
Assuming I can render to a file, I now have to invoke java. I tested
from the command line and this works fine. So now I have to do it from
the asp.net page, wait for it to finish, and then render the resulting
pdf file to the user. I assume all this code will be in the render
override?
Anybody called java before like this?
I'm thinking using a process object and something like the following
for the command. I've been researching and just doing java -jar as the
command doesn't work? Again anybody done this before and have code
examples?
start command /c java -jar thejar.jar options

Will Rickards
Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)

' create stream to store output
Dim objRendered As System.web.UI.HtmlTextWriter
Dim objFileWriter As System.IO.StreamWriter

' get file writer
objFileWriter = System.IO.File.CreateText(Server.MapPath(".") &
"\\PDF\\" & CStr(m_intReportNumber) & ".xhtml")

objRendered = New System.Web.UI.HtmlTextWriter(objFileWriter)

MyBase.Render(objRendered)

objFileWriter.Flush()
objFileWriter.Close()
objRendered.Flush()
objRendered.Close()

writer.Write("Done")

End Sub

Nov 19 '05 #1
2 2134
Hi Will,

I think this will help with Problem #1.

Ken
Microsoft MVP [ASP.NET]

' Render() sends server control content to a provided HtmlTextWriter
object
' We overrides the Render method
' Output is the HtmlTextWriter object.
Protected Overrides Sub Render _
(ByVal Output As HtmlTextWriter)
' Create a StringBuilder to hold the HTML
Dim sb As New StringBuilder
' Create an HtmlTextWriter
Dim tw As New HtmlTextWriter(New System.IO.StringWriter(sb))
MyBase.Render(tw)
' The following will fail if the ASPNET or impersonated account
' doesn't have write privileges in the root
Dim txtw As System.IO.StreamWriter = _
System.IO.File.CreateText("c:\htmltxt.txt")
' Write the page contents to the file just created
txtw.Write(sb.ToString())
txtw.Flush()
txtw.Close()
' Write the text to the HTML page
Output.Write(sb.ToString())
End Sub
"Will Rickards" <wi**********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
In my web application there is an interactive report. Then there need
to be a printable version a pdf. So I found this java tool csstoxslfo
and the java fop tool from apache that will take my xhtml and css and
convert it to pdf.

Problem 1)
I designed the aspx page to produce the xhtml as output. So how do I
save that rendered page to a file on the server? I think it involves
overriding the Render method. I wrote some code which appears below
that I don't know if it will work. Anybody done this before and have
code examples?

Problem 2)
Assuming I can render to a file, I now have to invoke java. I tested
from the command line and this works fine. So now I have to do it from
the asp.net page, wait for it to finish, and then render the resulting
pdf file to the user. I assume all this code will be in the render
override?
Anybody called java before like this?
I'm thinking using a process object and something like the following
for the command. I've been researching and just doing java -jar as the
command doesn't work? Again anybody done this before and have code
examples?
start command /c java -jar thejar.jar options

Will Rickards
Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)

' create stream to store output
Dim objRendered As System.web.UI.HtmlTextWriter
Dim objFileWriter As System.IO.StreamWriter

' get file writer
objFileWriter = System.IO.File.CreateText(Server.MapPath(".") &
"\\PDF\\" & CStr(m_intReportNumber) & ".xhtml")

objRendered = New System.Web.UI.HtmlTextWriter(objFileWriter)

MyBase.Render(objRendered)

objFileWriter.Flush()
objFileWriter.Close()
objRendered.Flush()
objRendered.Close()

writer.Write("Done")

End Sub

Nov 19 '05 #2
Thanks, that worked. Unfotunately, once I got the output the java tool
didn't like it as input so I have to track down those bugs.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mr Gordonz | last post by:
Hi All, I want to be able to save a file from the client's PC on the server. The tricky part is the aspx page is never actually seen by the user. Basically, I have a VB application running on...
9
by: Ivan Demkovitch | last post by:
Hi! I would like to know if I can save File on Server using server-side code? For example, I like to create thumbnail images and populate specific directory. Do I need specific permissions...
4
by: Nikhil Tayal | last post by:
Is there a way to write a file on the client machine from an aspx page? I've a custom query page and need to store the search criteria specified in an XML file on the user machine from my web page...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
8
by: DanB | last post by:
This is probably soooo simple but I can't seem to get it. I have a text file that I want users to download via a web page. I want the file to be saved to a default folder (or one that they...
0
by: WaterBug | last post by:
Is it possible?... We have an aspx page that serves as a form for data entry. When the user presses 'print' our desire is to populate an Excel worksheet with the data and serve the output in a...
1
by: =?Utf-8?B?U00=?= | last post by:
Hi, We have developed an application that transforms xsl into excel file and present xsl file to the user with data. We use open xml features of excel 2003. Our user is now asking for a chart to...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
3
by: evenlater | last post by:
I have an Access application on a terminal server. Sometimes my users need to export reports to pdf, rtf or xls files and save them to their own client device hard drives. They can do that right...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.