1
Answer

Read text file and insert into data table

sadhana belge

sadhana belge

8y
479
1
My text file is :
------------------------------------------------
| DVR alarm log. Start time: 26-11-2015 21:02:36 |
-------------------------------------------------
Alarm started. Guid: 844429225099264
Start time: 26-11-2015 21:03:17
Trigger DigitalInput
Channel: 1
Until acknowledged: No
Actions: Priority = Medium
DigitalOutput: output = 1
CameraRecording: camera = 1 time = 10 resolution = <camera default> framerate = <camera default>
CameraPrerecording: channel = 1 time = 10
-----------------------------------------------------
Alarm ended. Guid: 844429225099264
Start time: 26-11-2015 21:03:17
End time : 27-11-2015 17:51:03
Trigger DigitalInput
Channel: 1
Until acknowledged: No
Actions: Priority = Medium
DigitalOutput: output = 1
CameraRecording: camera = 1 time = 10 resolution = <camera default> framerate = <camera default>
CameraPrerecording: channel = 1 time = 10
-----------------------------------------------------
i want to output like this from Alarm ended data
 
Guid                               strattime                                      endtime
 844429225099264        26-11-2015 21:03:17                   27-11-2015 17:51:03
 
 
but i m not getting this type.i need get string after Alarm ended.
 
 
My code:
 
 
string filename = @"E:\DvrAlarmLog.txt";
string str = string.Empty;
if (File.Exists(filename))
{
string[] arrays = new string[7];
StreamReader sr = new StreamReader(filename);
String line = string.Empty;
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("ID"), new DataColumn("Start Date"), new DataColumn("End Date") });
StringBuilder sb = new StringBuilder();
List<string> list = new List<string>();
using (StreamReader srr = new StreamReader(filename))
{
//string[] lines = System.IO.File.ReadAllLines(filename);
//foreach (string linesingle in lines)
//{
// if (linesingle.Equals("Alarm ended"))
// {
while (srr.Peek() >= 0)
{
list.Add(srr.ReadLine());
}
// }
//}
}
for (int i = 13; i < list.Count; i++)
{
string[] strlist = list[i].Split('.');
foreach (string strdt in strlist)
{
if (!strdt.Contains("-----------------------------------------------------"))
{
//strdt +=
dt.Rows.Add(strlist[0], strlist[1], strlist[1]);
}
}
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
 
 
 
 
Answers (1)