I want to read in the content of multiple csv files in a list and use this list to split the contents in a datagridview. The problem is that with this code I only get the filenames but not the content of the files. How do I read in the content?
Below you can see the code.
public List<string> GetFileList(string strFilePath, bool SubFolders)
{
List<string> FileArray = new List<string>();
var fileContent = string.Empty;
var filePath = string.Empty;
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = "C:\\Users\\blabla\\Desktop\\folder\\files";
openFileDialog.Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
string[] Files = System.IO.Directory.GetFiles(strFilePath);
string[] Folders = System.IO.Directory.GetDirectories(strFilePath);
for (int i = 0; i < Files.Length; i++)
{
FileArray.Add(Files[i].ToString());
}
if (SubFolders == true)
{
for (int i = 0; i < Files.Length; i++)
{
FileArray.AddRange(GetFileList(Folders[i], SubFolders));
}
}
}
catch (Exception Ex)
{
throw (Ex);
}
return FileArray;
}
return FileArray;
}
}
I expected to use the contents in FileArray for a datagridview, but I only get the filenames. Thank you very much for your help!