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
System.IO
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)
{
files.AddRange(dirinfo.GetFiles(extension));
try
{
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>");
}
fb.Close();
//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...
Conclusion
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...