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. 

I also provide services on php, wordpress, joomla, codeigniter. If you need experts then hire me here - https://www.fiverr.com/share/0XozL 

 

Read 40286 times Last modified on Tuesday, 06 August 2019 08:12
Super User

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

Latest discussions

  • No posts to display.