Click here to Skip to main content
13,591,539 members
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 19 Mar 2006

A Simple HTML Builder Utility Class

, 19 Mar 2006
Rate this:
Please Sign up or sign in to vote.
When your application requirements for html formatting of texts (example: print page, e-mail text etc) are pretty simple, this simple builder class will save your development time.

Sample Image - HTML_Build_Clss.png


<?xml:namespace prefix = o /><o:p> 

When you develop a web based application, you need some texts to be converted to HTML tags for a convenient format. This is required especially when you have to send e-mail or show text in 'Print' page. Definitely there are lots of utility classes and tools are available in web. But fortunately some of my application requirements regarding HTML text were very simple and unfortunately I didn't find anything in the web to get a simple HTML builder utility to format my simple texts. However, as usual I decided to write an utility class, which is very simple to use.


Using the class


Let's look at the sample codes that use our Simplified HTML Builder Class.

public static void UseThis()
Ashraf.HTMLUtil util = new Ashraf.HTMLUtil();

util.AppendSubHeader("Sub Header");
util.AppendPara("Hello this is a para");
util.AppendPara("Hello this is the second para");
util.FormatToRowInColonSeparatedText("Label 1","Value 1", false);
util.FormatToRowInColonSeparatedText("Label 2","Value 2", false);
util.AppendPara("Hello this is footer para");
util.AppendSubHeader("Sub Footer");



At first you have to create an instance of "HTMLUtil" class. After then using different methods you can add your contents into this instance. Internally a System.Text.StringBuilder class instance is the container of all of the contents in the corresponding format. The utility class methods wrap all of contents to an html table so that the contents can easily be placed anywhere. Using the "HTMLUtil" instance you can add header, sub-header, normal texts, blank rows etc.

util.AppendSubHeader("Sub Header");
util.AppendPara("Hello this is a para");


However as you see in the code, there is a method named "FormatToRowInColonSeparatedText". This method appends colon separated row in the System.Text.StringBuilder container along with the passed parameters as caption and value. This is useful when you want to format html for database table fields.


util.FormatToRowInColonSeparatedText("Label 1","Value 1", false);



When you finish your texts to be built in desired formatting, you are ready to use that. You will get all the texts in proper formatted thru the "FormattedHTMLText" property of the class.




However, you can define the size of the fonts of header, sub-header, normal text and the font face for the builder class by the following properties.


public int HeaderTextSize{get;set;} //default size is 4 
public int SubHeaderTextSize{get;set;} //default size is 3 
public int NormalTextSize{get;set;} //default size is 2 
public string FontFace{get;set;} // default is "verdana"




Any advice or correction for this class will be highly appreciated.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Mohammad Ashraful Alam
Chief Technology Officer
Bangladesh Bangladesh
Mohammad Ashraful Alam is a Software Engineer, who is dedicated to Microsoft .NET based development. This Bangladeshi national is involved with project management and development of several US based software projects from his country. Already he has managed and developed 15 software projects, which are being used by several users of different countries, such as USA, Canada, Australia, and Bangladesh. While developing and managing a team, he contains and maintains a set of well defined engineering practices developed by him and other online developer community. Beside software development, he has also written several technical articles and research papers published by IEEE Computer Society and many other worlds recognized publishers.

Before becoming engaged with software development, he was involved with Bengali literature and several Bengali news papers as freelance journalist and published around 150 articles, essays and short stories.

Due to his willingness to give effort to improve and share better software development practices, Ashraf has awarded as “Most Valuable Professional” (MVP) in ASP.NET category by Microsoft for multiple times, since 2007.

When not engaged with technical stuffs, he likes to pass time with his friends, and family members, listens music or watches TV.

Check his portfolio at:

Check his blog:

Catch him thru mail: admin [attt] ashraful [dotttt] net (anti-spam text).

You may also be interested in...

Comments and Discussions

GeneralThe codes could be more decent Pin
Moim Hossain28-Nov-08 10:11
memberMoim Hossain28-Nov-08 10:11 
QuestionWhy? Pin
George L. Jackson19-Mar-06 5:20
memberGeorge L. Jackson19-Mar-06 5:20 
AnswerRe: Why? Pin
Mohammad Ashraful Alam19-Mar-06 20:33
memberMohammad Ashraful Alam19-Mar-06 20:33 
AnswerRe: Why? Pin
tomstrummer20-Mar-06 6:35
membertomstrummer20-Mar-06 6:35 
GeneralRe: Why? Pin
Mohammad Ashraful Alam20-Mar-06 8:30
memberMohammad Ashraful Alam20-Mar-06 8:30 
GeneralRe: Why? Pin
Mohammad Ashraful Alam20-Mar-06 8:32
memberMohammad Ashraful Alam20-Mar-06 8:32 
GeneralRe: Why? Pin
George L. Jackson20-Mar-06 12:59
memberGeorge L. Jackson20-Mar-06 12:59 
GeneralRe: Why? Pin
Mohammad Ashraful Alam20-Mar-06 20:42
memberMohammad Ashraful Alam20-Mar-06 20:42 
GeneralRe: Why? Pin
George L. Jackson21-Mar-06 0:27
memberGeorge L. Jackson21-Mar-06 0:27 
GeneralRe: Why? Pin
James Curran28-Mar-06 5:01
memberJames Curran28-Mar-06 5:01 
GeneralRe: Why? Pin
Mohammad Ashraful Alam28-Mar-06 20:22
memberMohammad Ashraful Alam28-Mar-06 20:22 
AnswerRe: Why? Pin
Sean Stapleton27-Mar-06 10:24
memberSean Stapleton27-Mar-06 10:24 
AnswerRe: Why? Pin
sdfgasdfsfgsdfg29-Mar-06 5:46
membersdfgasdfsfgsdfg29-Mar-06 5:46 
GeneralRe: Why? Pin
Mohammad Ashraful Alam29-Mar-06 7:12
memberMohammad Ashraful Alam29-Mar-06 7:12 
GeneralRe: Why? Pin
Ashaman31-Mar-06 2:00
memberAshaman31-Mar-06 2:00 
GeneralThanks for feedback Pin
Mohammad Ashraful Alam31-Mar-06 2:59
memberMohammad Ashraful Alam31-Mar-06 2:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180618.1 | Last Updated 19 Mar 2006
Article Copyright 2006 by Mohammad Ashraful Alam
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid