-1

I am looking for a way to import csv files with schma (.ini file). I want import the csv into a datatable. I don't want to use excel interop, because of known issues in running it on windows services.

Is there a way to do so in another tool or technology such as OpenXML?

I've already tested Aspose's and Syncfusion's tools - and it seems they can't offer a solution here. Would appreciate any help.

omer schleifer
  • 3,897
  • 5
  • 31
  • 42
  • Duplicate: http://stackoverflow.com/questions/217902/reading-writing-an-ini-file ? – Pragmateek Jun 23 '13 at 15:58
  • i am not looking for a way to read ini files. this is not a duplicate.I am looking for a way to export csv files with schema to datatable – omer schleifer Jun 23 '13 at 18:10
  • OK, because in your question you ask how to "*import csv files with schma (.ini file)*" and don't speak of DataTable. So please fix to ease further research. :) – Pragmateek Jun 23 '13 at 18:47

1 Answers1

1

You can do this with an ODBC connection, which treats the text file as a database. Just make sure the .ini file is in the same location as the text-file.

Recording a macro in Excel from the following steps will give you some base code to work with.

  • Data > Import External Data > New Database Query
    1. Select In Create New Data Source,
    2. choose a name
    3. select the driver - Microsoft Text Driver (*.txt, *.csv)
    4. click Connect and in ODBC Text Setup select the folder containing the csv file
    5. select a default table - the csv file (optional)

A similar process can be coded in C# without using Interop. It just uses a database connection, probably OleDbConnection.

Andy G
  • 19,232
  • 5
  • 47
  • 69