I have a text file with these contents
balamurugan,rajendran,chendurpandian
christopher
updateba
and i have read these files and searched for a keyword ba
and
i tried to write in another text file log.txt
but after executing my code
i am getting the third line only as
`LineNo : 2 : updateba`
I need to get both these lines
LineNo : 0 : balamurugan,rajendran,chendurpandian
LineNo : 2 : updateba
I am using this code to write to a text file
if (File.Exists(FilePath))
{
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader(FilePath);
while ((line = file.ReadLine()) != null)
{
if (line.Contains(regMatch))
{
DirectoryInfo Folder = new DirectoryInfo(textboxPath.Text);
if (Folder.Exists)
{
var dir = @"D:\New folder\log";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
File.WriteAllText(Path.Combine(dir, "log.txt"), "LineNo : " + counter.ToString() + " : " + line + "<br />");
}
else
{
Response.Write("<script language='javascript'>window.alert('Folder not found');</script>");
}
Response.Write("<script language='javascript'>window.alert('Pattern found');</script>");
Response.Write("LineNo : " + counter.ToString()+ " : " + line + "<br />");
}
else
{
Response.Write("<script language='javascript'>window.alert('Pattern not found');</script>");
}
counter++;
}
file.Close();
}
else
{
Response.Write("<script language='javascript'>window.alert('File not found');</script>");
}
i have used this samplelink text
Any suggestion???