Read All Notepad Files in a folder and merge all notepad files DATA in . aspx page

Posted by in ASP.NET category on for Intermediate level | Points: 250 | Views : 12216 red flag
Rating: 4.67 out of 5  
 3 vote(s)

In this article I am trying to fetch data more notepad file’s of a folder and merge them on an aspx page. In this sample article I have used 45 notepad files, firstly read them and then merge all files and write on a .aspx page. It’s a fast way to assemble all files to in a one webpage.

In .aspx Page

Firstly add this namespace


On Page Load Event

Write this code on Page load

protected void Page_Load(object sender, EventArgs e)



        DirectoryInfo dirinfo = new DirectoryInfo(Server.MapPath("TXTF/"));


        string validExtensions = "*.txt";

        string[] extFilter = validExtensions.Split(new char[] { ',' });

        ArrayList files = new ArrayList();


        foreach (string extension in extFilter)





                for (int i = 0; i < files.Count; i++)


                    StreamReader fb;

                    string filename = files[i].ToString();

                    fb = File.OpenText(dirinfo +  filename);

                    string input = null;

                    while ((input = fb.ReadLine()) != null)


                     Response.Write(input + "</br>");                                             



                    //return 0;




            catch (Exception ex)


                lblerror.Text = ex.ToString();






Whole Setup …

My all Notepad files in a TXTF folder. In aspx page you change your Folder name then if u want to fetch only one file so you comment the loop section... But these code works relay good...


In this article I have tried to merge all notepad file and print its data in a one webpage.  I think its will be helpful for every one...
Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: prabhakar parihar
Member Level:
Member Status: Member,MVP
Member Since: 1/12/2011 5:05:40 AM
Country: India
Best Regard's Prabhakar
7.6 Years exp. Software Development with ASP.NET C#

Login to vote for this post.

Comments or Responses

Posted by: Sutotpal on: 2/11/2011 | Points: 25
really nice article...
Posted by: Madhu.b.rokkam on: 2/14/2011 | Points: 25
Add foreach loop instead of for loop to read one or all files in a folder.
Posted by: Karthikanbarasan on: 2/14/2011 | Points: 25
Nice one!!!

Login to post response

Comment using Facebook(Author doesn't get notification)