Wednesday, 30 June 2021

Read Html File Using Streamreader In C#

6/30/2021 - By Pranav Singh 0

In this article i will show you how you can read and html file content or html file tag in you C# application. So for this article first we will create a new console application and create a test html file.



Now add some content into you html file.


After creation of the file don't forgot to put he template folder and file into your bin->debug folder as shown below other wise system will not be able to detect the template file. 


After this we will user Streamreader  to the file content. Here is the code which we use to read the content.

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace ConsoleApp1

{

       class Program

       {

        static void Main(string[] args)

        {

            using (StreamReader reader = new StreamReader("Template/TestHTMLFile.html"))

            {

                string line = "";

                StringBuilder stringBuilder = new StringBuilder();

                while ((line = reader.ReadLine()) != null)

                {

                       stringBuilder.Append(line);

                }

                   Console.WriteLine(stringBuilder.ToString());

                Console.ReadLine();

            }

        }

       }

}

 

Now run the application by putting a break point.  You will be able to read the detail.



Now check the final output.


Download

Tags:
About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top