/// <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);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        public DataSet ReadExcelData(string ExcelFilePath)
        {
            DataSet oResultDataSet = null;
            FileInfo oFileInfo = new FileInfo(ExcelFilePath);
            using (GenericParsing.GenericParserAdapter gp = new GenericParsing.GenericParserAdapter(ExcelFilePath, Encoding.UTF8))
            {
                gp.FirstRowHasHeader = true;
                gp.ColumnDelimiter = ',';
                oResultDataSet = gp.GetDataSet();
            }

            if (oResultDataSet != null && oResultDataSet.Tables.Count > 0)
                oResultDataSet.Tables[0].TableName = new FileInfo(ExcelFilePath).Name;

            return oResultDataSet;
        }
Esempio n. 5
0
        /// <summary>
        ///  This method read an csv file and returns a dataset.
        /// </summary>
        /// <param name="realfilePath"></param>
        /// <param name="dataSetname"></param>
        /// <returns></returns>
        private static DataSet GetDataSet(string realfilePath, string dataSetname = "dataset")
        {
            DataSet ds          = new DataSet(dataSetname);
            string  tmpFileName = GetTempFile(realfilePath);

            try
            {
                var extension = Path.GetExtension(tmpFileName);
                if (extension != null && extension.ToLower().Equals(".csv"))
                {
                    if (!File.Exists(tmpFileName))
                    {
                        throw new KryptonException("Error", Utility.GetCommonMsgVariable("KRYPTONERRCODE0037").Replace("{MSG}", realfilePath));
                    }
                    using (GenericParsing.GenericParserAdapter gp = new GenericParsing.GenericParserAdapter(tmpFileName, Encoding.UTF8))
                    {
                        gp.FirstRowHasHeader = true;
                        gp.ColumnDelimiter   = ',';
                        ds = gp.GetDataSet();
                    }
                }
                else
                {
                    ds = GetExcelDataSet(tmpFileName, dataSetname);
                }
            }
            finally
            {
                if (File.Exists(tmpFileName))
                {
                    try
                    {
                        File.Delete(tmpFileName);
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }
            //Validate for unwanted sheets
            ValidateSheetCount(ds, realfilePath);

            return(ds);
        }
Esempio n. 6
0
        public DataSet ReadExcelData(string ExcelFilePath)
        {
            DataSet  oResultDataSet = null;
            FileInfo oFileInfo      = new FileInfo(ExcelFilePath);

            using (GenericParsing.GenericParserAdapter gp = new GenericParsing.GenericParserAdapter(ExcelFilePath, Encoding.UTF8))
            {
                gp.FirstRowHasHeader = true;
                gp.ColumnDelimiter   = ',';
                oResultDataSet       = gp.GetDataSet();
            }

            if (oResultDataSet != null && oResultDataSet.Tables.Count > 0)
            {
                oResultDataSet.Tables[0].TableName = new FileInfo(ExcelFilePath).Name;
            }

            return(oResultDataSet);
        }
Esempio n. 7
0
        /// <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);
        }
Esempio n. 8
0
        /// <summary>
        ///   Get Dataset from the file specified.
        /// </summary>
        /// <param name="filePath">string : Filepath.</param>
        /// <returns>Dataset : dataset for the file.</returns>
        ///
        private static DataSet GetDataSet(string filePath)
        {
            DataSet dataset       = new DataSet();
            string  tmpFileName   = string.Empty;
            string  fileExtension = Path.GetExtension(filePath);

            try
            {
                tmpFileName = GetTemporaryFile(fileExtension, filePath);
                if (fileExtension != null && fileExtension.ToLower().Equals(".csv"))
                {
                    if (!File.Exists(tmpFileName))
                    {
                        Console.WriteLine(ConsoleMessages.FOD + filePath);
                    }
                    using (GenericParsing.GenericParserAdapter gp = new GenericParsing.GenericParserAdapter(tmpFileName, Encoding.UTF7))
                    {
                        gp.FirstRowHasHeader = true;
                        gp.ColumnDelimiter   = ',';
                        dataset = gp.GetDataSet();
                    }
                }
                else
                {
                    dataset = GetExcelDataSet(filePath);
                }
            }
            catch (Exception ex)
            {
                KryptonException.Writeexception(ex);
            }
            finally
            {
                File.Delete(tmpFileName);
            }
            return(dataset);
        }
Esempio n. 9
0
        /// <summary>
        ///  This method read an csv file and returns a dataset.
        /// </summary>
        /// <param name="realfilePath"></param>
        /// <param name="dataSetname"></param>
        /// <returns></returns>
        private static DataSet GetDataSet(string realfilePath, string dataSetname = "dataset")
        {
            DataSet ds = new DataSet(dataSetname);
            string tmpFileName = GetTempFile(realfilePath);
            try
            {
                var extension = Path.GetExtension(tmpFileName);
                if (extension != null && extension.ToLower().Equals(".csv"))
                {
                    if (!File.Exists(tmpFileName))
                    {
                        throw new KryptonException("Error", Utility.GetCommonMsgVariable("KRYPTONERRCODE0037").Replace("{MSG}", realfilePath));
                    }
                    using (GenericParsing.GenericParserAdapter gp = new GenericParsing.GenericParserAdapter(tmpFileName, Encoding.UTF8))
                    {
                        gp.FirstRowHasHeader = true;
                        gp.ColumnDelimiter = ',';
                        ds = gp.GetDataSet();
                    }

                }
                else
                {
                    ds = GetExcelDataSet(tmpFileName, dataSetname);
                }
            }
            finally
            {
                if (File.Exists(tmpFileName))
                    try
                    {
                        File.Delete(tmpFileName);
                    }
                    catch
                    {
                        // ignored
                    }
            }
            //Validate for unwanted sheets
            ValidateSheetCount(ds, realfilePath);

            return ds;
        }
Esempio n. 10
0
        /// <summary>
        ///   Get Dataset from the file specified.
        /// </summary>
        /// <param name="filePath">string : Filepath.</param>
        /// <returns>Dataset : dataset for the file.</returns>
        /// 
        private static DataSet GetDataSet(string filePath)
        {
            DataSet dataset = new DataSet();
            string tmpFileName = string.Empty;
            string fileExtension = Path.GetExtension(filePath);

            try
            {
                tmpFileName = GetTemporaryFile(fileExtension, filePath);
                if (fileExtension != null && fileExtension.ToLower().Equals(".csv"))
                {
                    if (!File.Exists(tmpFileName))
                    {
                        Console.WriteLine(ConsoleMessages.FOD + filePath);
                    }
                    using (GenericParsing.GenericParserAdapter gp = new GenericParsing.GenericParserAdapter(tmpFileName, Encoding.UTF7))
                    {
                        gp.FirstRowHasHeader = true;
                        gp.ColumnDelimiter = ',';
                        dataset = gp.GetDataSet();
                    }
                }
                else
                {
                    dataset = GetExcelDataSet(filePath);
                }
            }
            catch (Exception ex)
            {
                KryptonException.Writeexception(ex);
            }
            finally
            {
                File.Delete(tmpFileName);
            }
            return dataset;
        }