public Tuple<List<FieldImports>, bool> ReadTxtFile(string filePath)
{
string[] textData = System.IO.File.ReadAllLines(filePath);
string[] headers = textData[0].Split('\t');
DataTable dataTable1 = new DataTable();
foreach (string header in headers)
dataTable1.Columns.Add(header, typeof(string), null);
for (int i = 1; i < textData.Length; i++)
{
dataTable1.Rows.Add(textData[i].Split('\t'));
}
List<FieldImports> listDataColumn1 = new List<FieldImports>();
var columnNames = dataTable1.Columns.Cast<DataColumn>()
.Select(c => c.ColumnName)
.ToList();
List<FileDataModel> listDataResult = new List<FileDataModel>();
for (int columnIndex = 0; columnIndex < dataTable1.Columns.Count; columnIndex++)
{
List<FieldImports> listData = new List<FieldImports>();
FieldImports result = new FieldImports();
// result.ColumnName = dataTable1.Rows[i][i].ToString();
result.ColumnName = Convert.ToString(dataTable1.Rows[0][columnIndex]);
listData.Add(result);
}
//listDataResult.Add(listData);
for (int rowIndex = 0; rowIndex < dataTable1.Rows.Count; rowIndex++)
{
List<FieldImports> listData = new List<FieldImports>();
for (int columnIndex = 0; columnIndex < dataTable1.Columns.Count; columnIndex++)
{
FieldImports result = new FieldImports();
// result.ColumnName = dataTable1.Rows[i][i].ToString();
result.ColumnValue = Convert.ToString(dataTable1.Rows[rowIndex][columnIndex]);
listData.Add(result);
}
listDataResult.Add(listData);
}
// return new Tuple<List<FieldImports>, bool>(columnListData, false);
return null;
}
}
{
string[] textData = System.IO.File.ReadAllLines(filePath);
string[] headers = textData[0].Split('\t');
DataTable dataTable1 = new DataTable();
foreach (string header in headers)
dataTable1.Columns.Add(header, typeof(string), null);
for (int i = 1; i < textData.Length; i++)
{
dataTable1.Rows.Add(textData[i].Split('\t'));
}
List<FieldImports> listDataColumn1 = new List<FieldImports>();
var columnNames = dataTable1.Columns.Cast<DataColumn>()
.Select(c => c.ColumnName)
.ToList();
List<FileDataModel> listDataResult = new List<FileDataModel>();
for (int columnIndex = 0; columnIndex < dataTable1.Columns.Count; columnIndex++)
{
List<FieldImports> listData = new List<FieldImports>();
FieldImports result = new FieldImports();
// result.ColumnName = dataTable1.Rows[i][i].ToString();
result.ColumnName = Convert.ToString(dataTable1.Rows[0][columnIndex]);
listData.Add(result);
}
//listDataResult.Add(listData);
for (int rowIndex = 0; rowIndex < dataTable1.Rows.Count; rowIndex++)
{
List<FieldImports> listData = new List<FieldImports>();
for (int columnIndex = 0; columnIndex < dataTable1.Columns.Count; columnIndex++)
{
FieldImports result = new FieldImports();
// result.ColumnName = dataTable1.Rows[i][i].ToString();
result.ColumnValue = Convert.ToString(dataTable1.Rows[rowIndex][columnIndex]);
listData.Add(result);
}
listDataResult.Add(listData);
}
// return new Tuple<List<FieldImports>, bool>(columnListData, false);
return null;
}
}
No comments:
Post a Comment