Tuesday, January 21, 2014

OPEN A TEXT FILE USING C#


System.IO.StreamReader textIn=
new   System.IO.StreamReader(
new   System.IO.FileStream(dir, FileMode.OpenOrCreate, FileAccess.Read));
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("Key", typeof(string));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("LastName", typeof(string));
table.Columns.Add("Salary", typeof(string));
while (textIn.Peek() != -1)
{
string row = textIn.ReadLine();
string[] columns = row.Split('|');
table.Rows.Add(columns[0], columns[1], columns[2], columns[3]);
}
textIn.Close();
return table;

No comments:

Post a Comment

Stats


View My Stats

Contributors