Пример #1
0
        /// <summary>
        /// Reads a .csv file and turns it into a DataTable.
        /// </summary>
        /// <param name="filePath">The path to the file.</param>
        /// <returns>Returns a DataTable with content from the file.</returns>
        private static System.Data.DataTable DataTableFromCsv(string filePath)
        {
            System.Data.DataTable dtTemp = new System.Data.DataTable();
            StreamReader          sr     = new StreamReader(filePath);

            string line      = sr.ReadLine();
            char   separator = StringMaster.FindSeparator(line);

            string[] columnNames = line.Split(separator);
            foreach (string columnName in columnNames)
            {
                if (dtTemp.Columns.Contains(columnName))
                {
                    dtTemp.Columns.Add(columnName + " - DUBBEL");
                }

                else
                {
                    dtTemp.Columns.Add(columnName);
                }
            }
            // ------- hier werden de kolommen aan de datatable toegevoegd

            while (!sr.EndOfStream)
            {
                dtTemp.Rows.Add(sr.ReadLine().Split(separator));
            }
            sr.Close();
            return(dtTemp);
        }