Saturday, 12 January 2013 13:55

reading html file using StreamReader class by c#

Written by 
Rate this item
(2 votes)

if you want to read the content of any html file then
this tips can help you.StreamReader is used to read
the file and store data in Stringbuilder.you can modify
the Stringbuilder according to your need.

if you want to read the content of any html file then
this tips can help you.StreamReader is used to read
the file and store data in Stringbuilder.you can modify
the Stringbuilder according to your need.

Here the following method does that.the html file with
location is passed to the method.after getting the
content of the html file in StringBuilder,the method
returns it.then you can write back the content to the
html file again.

public static System.Text.StringBuilder ReadHtmlFile(string htmlFileNameWithPath)
{
System.Text.StringBuilder storeContent = new System.Text.StringBuilder();

try
{
using (System.IO.StreamReader htmlReader = new System.IO.StreamReader(htmlFileNameWithPath))
{
string lineStr;
while ((lineStr = htmlReader.ReadLine()) != null)
{
storeContent.Append(lineStr);
}
}
}

catch (Exception objError)
{
throw objError;
}

return storeContent;
}

If you have any kind of questions on this post or any topic, post your questions in
discussions/forum page in this website, you will get your answer.

Hope this tip/tutorial helped you a lot.Don't forget to like and share.

Read 19686 times Last modified on Monday, 19 August 2013 14:41
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

1 comment

Login to post comments