Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
This is My string

HTML
string st = "<div align="center" style=" width: 45.3mm;font-size: 8pt;font-family: calibri;background: white;"><div class="subpage">Welcome Naveen Store #5300/3 M.H.C Manimajra 160101 Chandigarh Punjab 160101 Ph: 9463946352 Fax: 1231231231 <table style=" width: 45.3mm;font-size: 8pt;font-family: calibri;background: white;"><tr><td>CARD#:</td><td>fgy65</td></tr> <tr><td>BALANCE:</td><td>$55</td></tr><tr><td>PAYMENT TYPE: </td><td>AMERICAN EXPRESS</td></tr><tr><td align="center" colspan="2">      7/18/2014 9:48:02 PM</td></tr></table>Thanks for Comes to my store.</div></div";


C#
StreamWriter objReader = null;
       try
       {
           //objReader = new StreamWriter(@"D:\test.html");
           objReader = new StreamWriter(@"F:\Richa222.txt");
           objReader.Write(st);
       }
       finally
       {
           objReader.Close();
       }


Now I want to convert this string to text file with all alignments styles and font and font family.. Please help me how I can do this.

Thanks
Posted
Updated 18-Jul-14 7:50am
v2

You can't even do it manually.

.txt files are not adequate in this case.

You should try to write a .doc file.
 
Share this answer
 
Comments
Christian Amado 18-Jul-14 16:00pm    
You can do it. HTML cannot be formatted in txt files, but you can save its content without problems.
You cannot apply HTML format in a txt file. But if you only want to save the html there you can...

Just from here[^].
C#
StreamWriter objReader = null;
try
{
    string encoded = HttpContext.Current.Server.HtmlEncode(st);
    objReader = new StreamWriter(@"F:\Richa222.txt");
    objReader.Write(encoded);
}
catch
{
    //catch error here
}
finally
{
    objReader.Close();
}

Hope it helps.
 
Share this answer
 
Comments
Christian Amado 18-Jul-14 15:59pm    
Why the downvote?
goathik 21-Jul-14 13:38pm    
it looks like it was me, I will put it 5 stars right now to prove you it wasn't, ok? here.

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