Click here to Skip to main content
13,456,901 members
Click here to Skip to main content
Add your own
alternative version


86 bookmarked
Posted 8 Mar 2003

ASC2XXX - Two classes for parsing delimited text files

, 8 Mar 2003
Rate this:
Please Sign up or sign in to vote.
Convert delimited text files to XML file or DataSet object
<!-- Add the rest of your HTML here -->

Turn a delimited text file:

Into a DataSet:

Or an XML file:


Two classes that illustrate one way to: read a delimited text file, parse the "fields" of data using regular expressions and move the data it into either an XML file or a DataSet object for direct use. 

.Net framework classes used:

  • System;//For strings and things
  • System.IO;//For reading and writing streams and files
  • System.Xml;//For creating and writing the XML file
  • System.Text.RegularExpressions;//For parsing the text file
  • System.Data;//to generate a DataSet

Concepts illustrated

  • Reading and writing files through stream objects
  • Parsing text using regular expressions
  • Generating a DataSet in memory from code and using it to fill a DataGrid control
  • Generating an XML file from code


The reason I wrote these classes is twofold:

  • I needed to write an application that would parse a web server log file (in W3C common log format) and put that data into a SQL server database. 
  • I needed a class that I could re-use in other applications where it was necessary to move data from a CSV text file into a database.

Using the code

Although very short, the code is commented heavily throughout and contains referenced hyperlinks to the MSDN articles that explain in more detail the .Net class being used at each point in the code where relevant.

This code is set to parse a web server log file, however it can easily be modified to parse any delimited text file and I've indicated in the comments where to do so. I've also included a commented out line of an alternate regular expression that can be used to parse comma delimited text files.

A file samplelog.txt is provided with the demo which contains a test web server log file.  I have mangled the IP Addresses for privacy, however the data is straight out of an Apache server log from our web server.

I've recently started using C# after many years of working in C++ so any constructive criticism would be welcome.


  • Original version: Feb.26.2003


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Member 96
Canada Canada
No Biography provided

You may also be interested in...

Comments and Discussions

Generaltab delimited files Pin
juliusPH19-Jan-04 16:48
memberjuliusPH19-Jan-04 16:48 
GeneralRe: tab delimited files Pin
John Cardinal19-Jan-04 17:26
memberJohn Cardinal19-Jan-04 17:26 
GeneralRe: tab delimited files Pin
juliusPH19-Jan-04 19:11
memberjuliusPH19-Jan-04 19:11 
GeneralRe: tab delimited files Pin
John Cardinal19-Jan-04 21:40
memberJohn Cardinal19-Jan-04 21:40 
GeneralRe: tab delimited files Pin
juliusPH19-Jan-04 22:32
memberjuliusPH19-Jan-04 22:32 
GeneralRe: tab delimited files Pin
simona441116-Apr-04 9:38
membersimona441116-Apr-04 9:38 
GeneralRe: tab delimited files Pin
John Cardinal16-Apr-04 12:51
memberJohn Cardinal16-Apr-04 12:51 
GeneralRe: tab delimited files Pin
oktayy27-Aug-04 11:10
sussoktayy27-Aug-04 11:10 
GeneralRe: tab delimited files Pin
Anonymous25-Aug-04 14:29
sussAnonymous25-Aug-04 14:29 
GeneralRe: tab delimited files Pin
oktayy25-Aug-04 14:29
sussoktayy25-Aug-04 14:29 
GeneralRe: tab delimited files Pin
John Cardinal25-Aug-04 18:41
memberJohn Cardinal25-Aug-04 18:41 
GeneralRe: tab delimited files Pin
Offlinesurfer18-Dec-04 14:26
memberOfflinesurfer18-Dec-04 14:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180322.1 | Last Updated 9 Mar 2003
Article Copyright 2003 by Member 96
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid