Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

CSV conversion for .NET

Posted on 2010-09-17
5
505 Views
Last Modified: 2012-05-10
I am looking for code or a component that will handle most of the different types of CSV files, like imbedded commas in a field.

Here are some of the conversions I have tried that did NOT work:

- .NET String.Split - will not handle imbedded commas
- OLEDB - sometimes thinks strings with numbers are numeric and removes leading zeros
- Lumneworks from CodeProject - exceptions too often and errors are difficult to understand
- FileHelpers - too much code to make it work

Thanks for any ideas
0
Comment
Question by:MisterT25
  • 3
5 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 33706045
seems straight foward, however I have to take your search for a solution as indication it may not be that simple....

Could you post a sample of the file you are trying to read? To my understanding, setting a streamreader's property to "has fields enclosedin quotes" should cover your scenario. Fields with commas in a CSV file are "usually" enclosed in double quotes.

So please, provise a sample ofthe file to take it foward?
0
 

Author Comment

by:MisterT25
ID: 33706059
Thanks for your reply.

The typical CSV has all the field quoted:  "Some Text","123456",...

Some CSV do not have quoted numbers:   "Some text",123456,...

Some CSV have imbedded commas:   "Some text","123,456",...

The first example is easy, but I get files from many different sources, so I never know what is next.  That is why I am looking for some robust code, or component.

Thanks
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 33706060
0
 

Author Comment

by:MisterT25
ID: 33706068
I think I  have tried TextFieldParser, and it would not handle the case where text is quoted, but numerics are not quoted.

I will try a quick test to see.

Thanks
0
 

Author Closing Comment

by:MisterT25
ID: 33706106
TextFieldParser seems to work well on some test files.  I will have to do more testing to be sure.  In the meantime, I will assign the points and thank you for your prompt response.

Thanks !
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exit the loop 4 49
start a process from a service 3 32
VB.net capture  result of a SQL query in variables 3 20
VB.NET String Settings and Temp Folder Question 3 54
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question