i need to write data to file in specified position with fixed length for each column with start position,end position and length of column. could you please alter my code or suggest.I have given sample length for each column
Column startposition endposotion Length
1 1 9 9
2 10 20 10
3 21 29 8
4 30 31 1
5 32 42 10
Output i needed to write in text file as:
00000 2014-09-23 01:36:22 F 2014-09-23
000000 2014-09-23 01:36:22 F 2014-09-23
000000000 2014-09-23 01:36:22 F 2014-09-23
below is code which i have created
string txt = string.Empty;
DataTable employeeTable = new DataTable("Employee");
employeeTable.Rows.Add("00000", "2014-09-23", "01:36:22", "F", "2014-09-23");
employeeTable.Rows.Add("000000", "2014-09-23", "01:36:22", "F", "2014-09-23");
employeeTable.Rows.Add("000000000", "2014-09-23", "01:36:22", "F", "2014-09-23");
DataSet ds = new DataSet("Organization");
ds.Tables.Add(employeeTable);
string filepath = Application.StartupPath + "\\" + "file.txt" ;
StreamWriter sw = null;
sw = new StreamWriter(filepath, false);
foreach (DataRow row in ds.Tables[0].Rows)
{
foreach (var item in row.ItemArray)
{
txt += item.ToString() + "\t";
}
txt += "\r\n";
}
sw.Write(txt);
sw.Close();
OutPut which iam getting from this code is, but this is wrong.
00000 2014-09-23 01:36:22 F 2014-09-23
000000 2014-09-23 01:36:22 F 2014-09-23
000000000 2014-09-23 01:36:22 F 2014-09-23
kindly rectify my problem.
What I have tried:
string txt = string.Empty;
DataTable employeeTable = new DataTable("Employee");
employeeTable.Rows.Add("00000", "2014-09-23", "01:36:22", "Falseis1", "2014-09-23", "01:36:22");
employeeTable.Rows.Add("000000", "2014-09-23", "01:36:22", "F", "2014-09-23", "01:36:22");
employeeTable.Rows.Add("000000000", "2014-09-23", "01:36:22", "F", "2014-09-23", "01:36:22");
DataSet ds = new DataSet("Organization");
ds.Tables.Add(employeeTable);
string filepath = Application.StartupPath + "\\" + "file.txt" ;
StreamWriter sw = null;
sw = new StreamWriter(filepath, false);
foreach (DataRow row in ds.Tables[0].Rows)
{
foreach (var item in row.ItemArray)
{
txt += item.ToString() + "\t";
}
txt += "\r\n";
}
sw.Write(txt);
sw.Close();