Import a CSV file

Snippet of code to import a CSV file using C#.
Be sure to add Microsoft.VisualBasic to your references.
// create an instance of our text field parser object.
using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(@"c:\temp\testimport.csv"))
{
	// set some properties on the parser object.
	parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
	parser.SetDelimiters(",");

	// keep reading the file until we get to the end.
	while (!parser.EndOfData)
	{
		// process each row. Read the fields in the current line.
		string[] fields = parser.ReadFields();
		
		// Process fields here
	}

	// accept all our changes to the table.
	tblRV.AcceptChanges();
}

Inspired by Reading CSV files using C#
Links for more information:


Last modified by Mohit @ 4/6/2025 10:08:35 PM