Using HtmlTextWriter class in x++


static void HTMLTextWriter(Args _args)
{
    HTMLTextWriter htw = new HTMLTextWriter();
    TextBuffer     txtBuffer = new TextBuffer();
    CCHTMLString   staticString;
    ;

    staticString = @'Test Message to show on browser.';
   
    htw.renderBeginTag(HtmlTextWriterTag::table());
    htw.renderBeginTag(HtmlTextWriterTag::tr());
    htw.write(staticString);
    htw.addAttribute(HtmlTextWriterAttribute::class_Attribute(), 's-vb');
    htw.addStyleAttribute(HtmlTextWriterStyle::width(), '26px');
    htw.addStyleAttribute(HtmlTextWriterStyle::padding_top(), '3px');
    htw.renderBeginTag(HtmlTextWriterTag::td());
    htw.addAttribute(HtmlTextWriterAttribute::src(), 'https://erpdax.files.wordpress.com/2015/07/cropped-microsoft-dynamics-ax.jpg');//get the image from web
    htw.addStyleAttribute(HtmlTextWriterStyle::width(), '550');
    htw.addStyleAttribute(HtmlTextWriterStyle::height(), '150');
    
    htw.renderBeginTag(HtmlTextWriterTag::img(), true);
    
    htw.renderEndTag();
    //close <Td>
    
    htw.renderEndTag();
    //close <Table>
    
    txtBuffer.setText(htw.getHtmlString());
       
    txtBuffer.toFile('C:\\DynamicsAX.html');  // please provide your path to save the file
    
}

The Result will be:
Test

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s