473,385 Members | 1,922 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,385 software developers and data experts.

Populate HTML From C# Console App?

233 100+
I have data in a database that I would like to use to populate a form to be printed out. My initial thought is to use an HTML template, populate it programatically, and then print the populated form. Is this the best method to print out data from a database in a manner that it can be easily read? If so, is this even possible from a console application? I realize that the terms form and console application do not mix, but I intend to have this be an unattended application.
Nov 2 '07 #1
10 4322
balabaster
797 Expert 512MB
I have data in a database that I would like to use to populate a form to be printed out. My initial thought is to use an HTML template, populate it programatically, and then print the populated form. Is this the best method to print out data from a database in a manner that it can be easily read? If so, is this even possible from a console application? I realize that the terms form and console application do not mix, but I intend to have this be an unattended application.
I assume you're using this mechanism to print out all the data in the database in a more readily readable format than from the tables inside the database. The alternative would be to generate a PDF but I don't see that this would be much more (if any) efficient than using the HTML template. With an HTML (or probably XML) template, your application really just needs to traverse the nodes and populate the relevant node's innerHTML or innerText which could be done using classes from the XML namespace. It's really just a case of applying an XSL stylesheet to the XML to give it a pretty format before sending it to the printer. I've not tried using the XML classes on HTML but given that the structure is so closely related, I would hazard a guess that it could be made to work without too much effort.
Nov 2 '07 #2
mcfly1204
233 100+
I assume you're using this mechanism to print out all the data in the database in a more readily readable format than from the tables inside the database. The alternative would be to generate a PDF but I don't see that this would be much more (if any) efficient than using the HTML template. With an HTML (or probably XML) template, your application really just needs to traverse the nodes and populate the relevant node's innerHTML or innerText which could be done using classes from the XML namespace. It's really just a case of applying an XSL stylesheet to the XML to give it a pretty format before sending it to the printer. I've not tried using the XML classes on HTML but given that the structure is so closely related, I would hazard a guess that it could be made to work without too much effort.
I am now leaning towards using XSLT given it seems most appropriate; I have XML files and I need the data style in a readable manner. I do not know how familiar you are with using XML stylesheets, but I am having an issue with the value of statement. From what I have read, the stylesheet should hold a line such as:

<td><xsl:value-of select="XPath"></td>

where XPath is the appropriate XPath for the needed value. Currently, when I open the XML document with an added line to include the XSLT, no value is shown from the XPath. Is there a possibility that I might be missing a step here?
Nov 6 '07 #3
mcfly1204
233 100+
Cannot figure out why my xsl:value-of select statements are not returning any values.

the XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="P3A4StyleSheet.xsl"?>

<Pip3A4PurchaseOrderRequest>
<fromRole>
<PartnerRoleDescription>
<ContactInformation>
<contactName>
<FreeFormText>Mr. Smith</FreeFormText>
</contactName>
<telephoneNumber>
<CommunicationsNumber>687-5309</CommunicationsNumber>
</telephoneNumber>
<EmailAddress>smith@smith.com</EmailAddress>
</ContactInformation>
</PartnerRoleDescription>
</fromRole>
</Pip3A4PurchaseOrderRequest>

The stylesheet:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http:www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" />

<xsl:template match="/">
<html>
<body>
<h2>ePSA Purchase Order</h2>
<table border="1">
<tr>
<th align="left">P.O. Element</th>
<th align="left">P.O. Value</th>
</tr>
<tr>
<td>From Contact Name</td>
<td><xsl:value-of select="/Pip3A4PurchaseOrderRequest/fromRole/PartnerRoleDescription/ContactInformation/contactName/FreeFormText" /></td>
</tr>
<tr>
<td>From Contact Email</td>
<td><xsl:value-of select="/Pip3A4PurchaseOrderRequest/fromRole/PartnerRoleDescription/ContactInformation/EmailAddress" /></td>
</tr>
<tr>
<td>From Contact Telephone</td>
<td><xsl:value-of select="/Pip3A4PurchaseOrderRequest/fromRole/PartnerRoleDescription/ContactInformation/telephoneNumber/CommunicationsNumber" /></td>
</tr>
<tr>
<td>Misc.</td>
<td><xsl:value-of select="." /></td>
</tr>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
Nov 6 '07 #4
mcfly1204
233 100+
The answer to my question was incorrect XPaths.
Nov 7 '07 #5
Plater
7,872 Expert 4TB
Hmm, are you able to print with formating?
I auto-generate a string of html that I use to send in an email (html emails have a nicer organization)
But I have not come up with a viable way to automatically print it out formated as html. (I can do plain text just fine)
What are you using?
Nov 7 '07 #6
balabaster
797 Expert 512MB
Hmm, are you able to print with formating?
I auto-generate a string of html that I use to send in an email (html emails have a nicer organization)
But I have not come up with a viable way to automatically print it out formated as html. (I can do plain text just fine)
What are you using?
Plater, try spitting it at the printer through an internet explorer class and use it's formatting engine to do the work for you. It's not the ideal method, but it will take most of the hard work out of it. The only thing I haven't had time to figure out is how to make it print to a printer other than your default printer...i.e. if you have 3 printers installed and you wanted to send it to your photo printer instead of your every day black and white draft printer.
Nov 7 '07 #7
Plater
7,872 Expert 4TB
Plater, try spitting it at the printer through an internet explorer class and use it's formatting engine to do the work for you. It's not the ideal method, but it will take most of the hard work out of it. The only thing I haven't had time to figure out is how to make it print to a printer other than your default printer...i.e. if you have 3 printers installed and you wanted to send it to your photo printer instead of your every day black and white draft printer.
That is exactly how I had been doing it, however the problem occured where the ASP.NET page I had did not allow the creation of the IE object (something about wrong thread apartment state, which I didn't believe I had control over in asp.net)
Nov 7 '07 #8
balabaster
797 Expert 512MB
That is exactly how I had been doing it, however the problem occured where the ASP.NET page I had did not allow the creation of the IE object (something about wrong thread apartment state, which I didn't believe I had control over in asp.net)
That sounds like a whole different topic...
Nov 7 '07 #9
Plater
7,872 Expert 4TB
That sounds like a whole different topic...
Well I had been watching this topic, as a valid solution could prove fruitful to my own troubles.
Unfortunatly best I can come up with is a seperate proccess that would be started to print things.
Nov 7 '07 #10
balabaster
797 Expert 512MB
Well I had been watching this topic, as a valid solution could prove fruitful to my own troubles.
Unfortunatly best I can come up with is a seperate proccess that would be started to print things.
I'll keep my eye out for an imaginitive solution...it seems to me that there must be something simpler than going down the whole PrintDocument route and doing all your own formatting...
Nov 7 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: alex | last post by:
Hi, I am looking for a way to populate an HTML table from an external local text file which looks like this: DATE/TIME LAT. LON. DEPTH. ML....
2
by: C. David Rossen | last post by:
Hello: I have a registration form for classes. Each class has a fee. I have a drop down box whereby the user chooses his class. There is a textbox with the associated fee. I would like to...
1
by: jzhang29 | last post by:
I have a JSP page and it contains a dropdown list called Office. What I try to do is: When I select different office from this list, the information of office (address, phone,etc) will be...
0
by: dgoel | last post by:
Hi, I Have a text file & I want to open it in excel sheet ( withou importing). I have written code for it, but it is not opening exce sheet. It opens the text file, but does not create a excel...
7
by: Sharon | last post by:
I have successfully loaded a DataSet object with a XML schema (XSD). Now I wish to populate the tables that was created in the DataSet. I have an XML file/string that contain all the needed data...
2
by: §iD` | last post by:
Hi! I would like to create a virtual folder (which I want to mount) and populate managing his content by a DLL or something like that in VB.NET (2.0). How can I acomplish this? Thanks to...
3
by: Chifo | last post by:
hello. i have a problem with a populate html table with data from table here it's the problem two querys retrieving data from table, one of querys show me a colletion of data from 6:00 am to...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
2
by: dbuchanan | last post by:
I intend to populate a listBox from the database for later use. (the intent for doing this is irrelevant to this questrion) The list box when hidden is never populated. The list box when visible...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.