Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

One of my requirement is that a user can upload with various file like CSV, excel, Fixed file format, XML etc.

Can i have any common parser which can parse any file in the given list and convert it into dataset or datatable for DB insertion.

Also in future if any new file format comes which is not in the list, it should be very easy to attach a logic with that file format.

i am working on asp.net and .net 3.5 and MSSQL2008.
Posted
Comments
[no name] 21-Jan-13 6:22am    
If you have any questions then add that in the comment section not in solution section.

No.
There is no such thing as a "parser for any file format", and though it would be possible to create a class that could be expanded to parse new formats, there are so many different formats (just the number of different file formats Microsoft have used over the years is staggering) that it is impractical to try and create a single parser to do all jobs.

Think of what files you need to support, and look at finding existing parsers for each of them. (They will all work in radically different ways, so getting them to work "nicely" together is going to be a fair amount of work anyway)
 
Share this answer
 
Comments
[no name] 21-Jan-13 6:21am    
Thanks a lot OriginalGriff657. please see here Pinank's comments

We can read any file and create a stream reader. but do we need a seperate logic to read from stream reader and create dataset?

can this work:
i create an object from streamreader and object will create a dataset?
For the formats you listed, you might try OLEDB[^].
The "etc." and the "fixed format" on the file format list distroys the above mentioned approach, though.
Cheers
Andi
 
Share this answer
 
Comments
Pinank_CD 22-Jan-13 3:23am    
Hi Andreas,

you are corret on your part, but in the market there are 3rd party parser available, even they must be using some logic build the data out of a stream. dont know but there should be some solution to other formats as well after all everything is bit of piece. :)
Andreas Gieriet 22-Jan-13 4:11am    
I don't know what your understanding of a parser is. I mean, you can always implement a kind of "chain of commands" gerneral purpose parser that consists of a lot of parser plugins. Each plugin must decide if it can parse the piece of data (and doit if possible, or say "no" and let the chain-of-command hand over to the next).
The challenge for such a plugin are
1) how to easily detect if it can parse (either some header magic (e.g. sh-bang), or some brute-force attempt to parse and if error, say "no").
2) get the spec for the format (e.g. you hardly get a spec for Excel format)
3) parse the whole universe of a given spec (e.g. Excel again: strip away all the rendering, graphics, font, etc. data and extract only the data - what about formulas: evaluate or as formula? etc.)

You do not want to invent all that.
Search the net an download/buy ready to use solutions.

Building that yourself will cost you more money/time than you probably have/are willing to spend.

Andi
Pinank_CD 22-Jan-13 4:21am    
i think what you are saying is logically correct. there can be lots of formats and each one of them can have different methods to access. Same comments were posted by OriginalGriff. thank you all of you. marking this as a solution.
Andreas Gieriet 22-Jan-13 4:34am    
Thanks for accepting this as a "solution", even I could not really "solve" your primary request.
Cheers
Andi
PS: To reply to a comment, click on the top right of the comment - there is a "reply" link.
Pinank_CD 22-Jan-13 4:39am    
Hey Andi,

i will be eager to share my solution, in case if succeed with some new solution. how can i reach you?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900