Process CSV Files with VB.NET

An example CSV file containing the following record

"Firstname", "Surname", "Date-Time-Entered","Items"
"Trevor","O Connell","26/02/2009 18:01:00","12"

Dim fName, sName,sDate,sTime,readLine,strfilename,textdelimiter as String
Dim tmpDate as DateTime
Dim nItems as Integer
Dim splitLine() As String
Dim objStreamReader As StreamReader

filename = Server.MapPath("~/app_data/sampledata.csv")
objStreamReader = File.OpenText(filename)

' Read and Ignore Header
readLine = objStreamReader.ReadLine()

textdelimiter = ","`

While objStreamReader.Peek() <> -1
readLine = objStreamReader.ReadLine()

' Check if its a blank line if so ignore.
If LTrim(RTrim(readLine)) <> "" Then
splitLine = Split(readLine, textdelimiter)
sFname = = splitout(0).Replace("""", "")
sSname = = splitout(1).Replace("""", "")
tmpDate = splitout(2).Replace("""", "")
sDate = tmpDate.Date.ToShortDateString.ToString
sTime = tmpDate.TimeOfDay.ToString
nItems = splitout(3).Replace("""", "")
' Process the each record as you wish

End If
End While


Popular posts from this blog

ActiveMQ, easy to use open source message oriented middleware (MOM)

Basic Send Message to MQ with Java and IBM MQ JMS

Apache Apollo