/// <summary> /// Parses tab-delimited file and returns DataTable object with the entire file /// </summary> public static DataTable BuildFromTabFile(string FileName) { using (GenericParsing.GenericParserAdapter parser = TabDelimitedParserFactory(FileName)) { return(parser.GetDataTable()); } }
/*public static IList<string> GetColumnNamesFromCSV(string csvFilePath) * { * using (var reader = new StreamReader(csvFilePath, Encoding.UTF8)) * { * using (var csv = new CsvReader(reader, CreateCsvConfiguration())) * { * csv.Read(); * csv.ReadHeader(); * * List<string> headerRow = csv.Context.HeaderRecord.ToList(); * return headerRow; * } * } * }*/ public static DataTable LoadCSVtoDataTable(string csvFilePath) { var adapter = new GenericParsing.GenericParserAdapter(csvFilePath, Encoding.UTF8); adapter.FirstRowHasHeader = true; adapter.ColumnDelimiter = csvColumnDelimiter; DataTable sourceDataTable = adapter.GetDataTable(); return(sourceDataTable); }
/// <summary> /// Reads a CSV file and returns a DataTable /// </summary> /// <param name="path"></param> /// <param name="isFirstRowHeader"></param> /// <returns></returns> public static DataTable GetDataTableFromCsv(string path, bool isFirstRowHeader) { path = Path.GetFullPath(path); var adapter = new GenericParsing.GenericParserAdapter(path); adapter.FirstRowHasHeader = true; DataTable dt = adapter.GetDataTable(); return(dt); }
/// <summary> /// Reads a OSI table dbdump returns a DataTable /// </summary> /// <param name="path"></param> /// <returns></returns> public static DataTable GetDataTableFromOsiDbdump(string path) { path = Path.GetFullPath(path); using StreamReader reader = File.OpenText(path); reader.ReadLine(); reader.ReadLine(); reader.ReadLine(); reader.ReadLine(); reader.ReadLine(); var adapter = new GenericParsing.GenericParserAdapter(reader) { FirstRowHasHeader = true }; DataTable dt = adapter.GetDataTable(); //delete any empty keys at the end of the table while (string.IsNullOrWhiteSpace(dt.Rows[dt.Rows.Count - 1]["Key"].ToString())) { dt.Rows[dt.Rows.Count - 1].Delete(); } return(dt); }