Create HTML using HtmlTextWriter class in dynamics ax


Description:-

HtmlTextWriter class is used to output properly formed HTMLinto a web page.  TheHtmlTextWriter allows the developer to code attributes, style attributes, andtags etc.

The HtmlTextWriter class permits the developer to generatepage output in a non-browser specific way; that is to say, the burden ofdeveloping alternative Markup is typically removed by using theHtmlTextWriter.  The HtmlTextWriter class exposes properties, fields, andmethods that permit the developer to format HTML 4.0 compliant output. 

For example, in the job below i added static string and  an image using the HtmlTextWriter class. 

Code:-

static void HTMLTextWriter(Args _args)
{
    HTMLTextWriterhtw = new HTMLTextWriter();
    TextBuffer     txtBuffer = new TextBuffer();
    CCHTMLString   staticString;
    ;
    staticString = @'At Solugenix we know our success results from taking a long term view in all our relationships: clients, employees, industries and technologies.;   
    htw.renderBeginTag(HtmlTextWriterTag::table());   
    htw.renderBeginTag(HtmlTextWriterTag::tr());   
    htw.write(staticString);   
    htw.addAttribute(HtmlTextWriterAttribute::class_Attribute(), 'ms-vb');   
    htw.addStyleAttribute(HtmlTextWriterStyle::width(), '26px');   
    htw.addStyleAttribute(HtmlTextWriterStyle::padding_top(), '3px');   
    htw.renderBeginTag(HtmlTextWriterTag::td());   
    htw.addAttribute(HtmlTextWriterAttribute::src(), 'http://www.holidayegreetingssite.com/index_files/image3121.jpg’);//getthe image from web   
    htw.addStyleAttribute(HtmlTextWriterStyle::width(), '100');   
    htw.addStyleAttribute(HtmlTextWriterStyle::height(), '50');   
    htw.renderBeginTag(HtmlTextWriterTag::img(), true);
    htw.renderEndTag();
    //close <Td>
    htw.renderEndTag();
    //close <Table>   
    txtBuffer.setText(htw.getHtmlString());   
    txtBuffer.toFile('f:\\DynamicsAX.html'); //please provide your path to save thefile
}

Related Posts

Previous
Next Post »

Thanks for comments.....