The CSV file itself is a TXT file. So... you can read the file stream through FileStream.
The following code:
Public void GetCSV1 ()
{
FileStream fs = new FileStream ("D: \ ReportLowIDAndHighID.csv", FileMode. Open, FileAccess. Read );
// FileStream fs = new FileStream ("c: \ sample.xls", FileMode. Open, FileAccess. Read );
StreamReader sr = new StreamReader (fs );
String t = sr. ReadToEnd ();
}
There is another way to read CSV files
Public void GetCSV ()
{
String strConn = string. format ("Provider = Microsoft. jet. OLEDB.4.0; Extended Properties = 'text; HDR = Yes; FMT = delimited'; Data Source = D: \ "); // connect Data. Data Source is the directory of the CSV file
OleDbConnection conn = new OleDbConnection (strConn );
DataTable dt1 = new DataTable ();
String SQL = "select * from ReportLowIDAndHighID.csv ";
Try
{
Conn. Open ();
OleDbDataAdapter dr = new OleDbDataAdapter (SQL, conn );
DataSet ds = new DataSet ();
Dr. Fill (ds, "table1 ");
Dt1 = ds. Tables ["table1"];
}
Catch (Exception e)
{
Throw e;
}
Finally
{
Conn. Close ();
}
}
This method may cause garbled characters. Not resolved. Studying...