Write Rows from DataTable to Text File

前端 未结 6 1576
面向向阳花
面向向阳花 2021-02-14 11:31
public void GenerateDetailFile()
{
  if (!Directory.Exists(AppVars.IntegrationFilesLocation))
  {
    Directory.CreateDirectory(AppVars.IntegrationFilesLocation);
  }

          


        
6条回答
  •  抹茶落季
    2021-02-14 12:28

    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

提交回复
热议问题