Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
Read text file and insert into data table
sadhana belge
Nov 28 2015 11:14 AM
458
Reply
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();
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
How to read template from xml file using Dataset
C# Ssh Connection