1

Is there an easy way to read the contents of a CSV file/XML Sitemap (will just be a bunch of URLS) into a Datagrid view in a win form?

Thankyou

dtsg
  • 4,408
  • 4
  • 30
  • 40

4 Answers4

1

How about using FileHelpers. This can read delimited or fixed length files which you map to a type.

In your case the type will contain a string Url.

Put these into a collection and databind to that.

Something like:

[DelimitedRecord(",")]
public class Row
{
    public string Url;

}

and then to read into memory:

FileHelperEngine<Row> engine = new FileHelperEngine<Row>();
engine.ReadFile("input.csv");
1

There is quite a good article for doing this located here: http://www.codeproject.com/Articles/16951/Populating-data-from-a-CSV-file-to-a-DataGridView the code is in VB.NET but it should be easy to convert either using your own knowledge or using an online conversion tool such as www.developerfusion.com/tools/convert/vb-to-csharp/

Apqu
  • 4,880
  • 8
  • 42
  • 68
0

read the csv file to a dataset, and then set the dataset as the datasource of the dataGridView . Follow this link for populating the dataset: http://www.java2s.com/Code/CSharp/Database-ADO.net/ReadcommaseparatedvalueintoDataSet.htm

yoozz
  • 247
  • 2
  • 15
0

CSV files are common data sources accessible from OLEDb data provider. Fill a DataTable with them and then set the DataTable as DataSource for the GridView.

See here.

Community
  • 1
  • 1
Alberto De Caro
  • 5,147
  • 9
  • 47
  • 73