Click here to Skip to main content
15,896,526 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
I need to print html text using c#.

Now html looking

string strHTML="<html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";
Posted
Comments
Rana Zarour 26-Dec-13 4:10am    
where do you need to print it ?

Hi
Try this..


C#
protected void Button1_Click(object sender, EventArgs e)
       {

           string strHTML = "<html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";
           LiteralControl literal = new LiteralControl();
           literal.Text = strHTML;
           this.Controls.Add(literal);
       }


fore more info : literal controls[^]
 
Share this answer
 
Hi,

you can use Webbrowser to print HTML.
See the below link.

http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.print.aspx[^]
 
Share this answer
 
I assume that you want the HTML to appear on your site as text, rather than be actioned as HTML?
If so, then just use HtmlEncode:
C#
string strHTML = Server.HtmlEncode("<html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>");
 
Share this answer
 
Dear Mr.arthik mahalingam


protected void Button1_Click(object sender, EventArgs e)
{

string strHTML = "<html><body>

My First Heading

My first paragraph.

</body></html>";
LiteralControl literal = new LiteralControl();
literal.Text = strHTML;
this.Controls.Add(literal);
}

In this solution We recieved html text in literal, How to print this literal text?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900