C#: How to read html file in side asp.net application by c#.


In c# We can read data from Html file with help of System.IO.StreamReader(htmlFileNameWithPath).

 +Calling Function
    protected void Page_Load(object sender, EventArgs e)
        string htmlContent = Convert.ToString(ReadHtmlFile(Server.MapPath("~\\HtmlTemplateExample.html")));

Here Server.MapPath(“~\\EmailTemplate.html”)) is used to map exact path of your file which is currently you have attatched in your solution.

 +Code Example 
    /// <summary>
    /// Read Html file 
    /// </summary>
    /// <param name="htmlFileNameWithPath"></param>
    /// <returns></returns>
    public static System.Text.StringBuilder ReadHtmlFile(string htmlFileNameWithPath)
        System.Text.StringBuilder htmlContent = new System.Text.StringBuilder();
        string line;
            using (System.IO.StreamReader htmlReader = new System.IO.StreamReader(htmlFileNameWithPath))

                while ((line = htmlReader.ReadLine()) != null)
        catch (Exception objError)
            throw objError;

        return htmlContent;

Page Keyword: How to read data from html file in c#, Read html content from c#, Reading data from file by c#


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s