hasib budi

hasib budi

  • NA
  • 20
  • 5.2k

open csv one by one using loop

Sep 17 2020 3:27 AM
hi,
 
I have a program that can read CSV. How to make it loop to read CSV file and insert. Example one folder has 2 CSV file. The program will read 1.csv and insert. And then 2.csv and then insert. Please help me.
  1. DirectoryInfo info = new DirectoryInfo(@"C:\folder\apoo");  
  2. FileInfo[] filess = info.GetFiles().OrderByDescending(p => p.LastWriteTime).ToArray();  
  3.   
  4. string latestfile = "";  
  5. DateTime lastupdate = DateTime.MinValue;  
  6.   
  7. var connString = "path";  
  8.   
  9. foreach(FileInfo filess2 in filess)  
  10. {  
  11.     if (filess2.LastWriteTime > lastupdate)  
  12.     {  
  13.         lastupdate = filess2.LastWriteTime;  
  14.         latestfile = filess2.Name;  
  15.     }  
  16.     Console.WriteLine("File : " + latestfile);  
  17.     Console.WriteLine("LWT : "+lastupdate);  
  18. }  

Answers (1)