score:0

        static datatable getdatatablefromcsv(string path, bool isfirstrowheader)
        {
            datatable datatable = null;

            using (var instream = new filestream(path, filemode.open, fileaccess.read, fileshare.readwrite))
            using (var sr = new streamreader(instream))
            {
                string line;
                while ((line = sr.readline()) != null)
                {
                    var fields = line.split(',');

                    if (datatable == null) // create datatable based on header row
                    {
                        datatable = new datatable();
                        foreach (var field in fields)
                            datatable.columns.add(new datacolumn(field));
                        continue; // don't add header row to rows collection
                    }

                    datatable.rows.add(fields);
                }
            }

            return datatable;
        }

Related Query

More Query from same tag