public void GenerateDetailFile()
{
if (!Directory.Exists(AppVars.IntegrationFilesLocation))
{
Directory.CreateDirectory(AppVars.IntegrationFilesLocation);
}
The below code will let you to write text file each column separated by '|'
foreach (DataRow row in dt.Rows)
{
object[] array = row.ItemArray;
for (int i = 0; i < array.Length - 1; i++)
{
swExtLogFile.Write(array[i].ToString() + " | ");
}
swExtLogFile.WriteLine(array[array.Length - 1].ToString());
}
Reference link