convert text file to html

Posted by Sukesh.Net under C# on 10/23/2012 | Points: 10 | Views : 3091 | Status : [Member] | Replies : 0
i want to read text file and then we need to we need to convert that text to int html page. i did but its not converting all data.. i have 3048 lines in text files. but i got 2496 lines. please suggest me

below code i am using

string sTempFileName = @"C:\Documents and Settings\rajesh\Desktop\New Folder\sampleText.txt.html";

//StreamWriter sw = new StreamWriter(sTempFileName, false, System.Text.Encoding.Unicode);
StreamWriter sw = new StreamWriter(sTempFileName, true, System.Text.Encoding.Unicode);

sw.Write("<html>");
sw.Write("<body>");
foreach (string s in lstRow)
{
sw.Write(ConvertToHTML(s));
}
sw.Write("</body>");
sw.Write("</html>");
}
}
private string ConvertToHTML(string value)
{
if (string.IsNullOrEmpty(value))
return "";
else
{

value = value.Replace('"', '"'); //replace int value 94 to normal double quote
value = value.Replace('"', '"'); //replace int value 93 to normal double quote
value = value.Replace(''', '\''); //replace int value 92 to normal single quote
//value = HttpUtility.HtmlEncode(value);
string s,sNew;


StringReader sr = new StringReader(value);
StringWriter sw = new StringWriter();

//Loop while next character exists
while (sr.Peek() > -1)
{
string temp = sr.ReadLine();
sw.Write(temp+"<br>");
}
//sw.Write("\n");
//sw.Write("\r\n\r\n");
return sw.GetStringBuilder().ToString();
}

Thanks
Sukesh



Responses

(No response found.)

Login to post response