I am generating dynamic HTML from c# application, By using string builder the html tags are appended and finally forming full html. In all the stringbuilder i am replacing html placeholders with c# object.
The html which am building is complex one, i need to fill up the placeholder from c# properties and sometimes database call. Am not having XML so not using XSLT. Since my html file huge and lot of string buider is required. Most of the sections are repeated based on business logic.
Everything is working fine now, i want to move away hardedcoded html string from stringbuilder, because maintenence will tough later on. Any best suggestions to get rid of hardcoded html from console application.
Performance wise, is it good to use lot of string builder( atleast 500 stringbuilder am using) For example, my html split is as below
- header part
- Body part
2.1 section1
2.1.1 section 1.1
2.1.2 section 1.2
2.1.3 section 1.3
2.2 section2
2.3 section3
2.4 section4
2.5 section5
3.Footer Part - Temrs and conditions
I have just provided few lines of code here for your reference.
Code Sample:
htmlStringBuilder.Append("<table class=\"paddingIndendation\" style=\"width: 100%;\" border=\"1\">");
htmlStringBuilder.Append(string.Format("<tr><td>Location {0}</td><td>:</td><td>{1}</td></tr>", location.LocationNumber, location.AddressLine1));
htmlStringBuilder.Append(string.Format("<tr><td colspan=\"2\" style=\"text-align:right;\"></td><td>{0}</td></tr>", location.AddressLine2));
htmlStringBuilder.Append(string.Format("<tr><td colspan=\"2\" style=\"text-align:right;\"></td><td>{0} {1}</td></tr>", location.PostalCode, location.City));
htmlStringBuilder.Append(string.Format("<tr><td colspan=\"2\" style=\"text-align:right;\"></td><td>{0} {1}</td></tr>", this.Id,this.StartEffectiveDate));
I want to move the hardcorded html content to somewhere(May be to file or resource file) and replace the placeholders with properties. Can anyone advise best way to do it.
.aspx
markup..