How do I access a text file on a PocketPC from VB.net?


A

Adrian J Borg

Hi all,

Could anyone please point me in the right direction on how to open and read
a text file in vb.net on a PocketPC, using the compact framework?

The text file (on the PocketPC) will consist of a number rows (records) each
having a number of fields delimeted by some character.

I want to be able to read the records and eventually also break them down
into fields.

Some sample coding would help immensely.

Is there something like an ODBC driver for text that I can use on the
PocketPC?

Thanks

Adrian
 
Ad

Advertisements

P

Peter Foot [MVP]

P

Peter Foot [MVP]

Its fairly straight-forward with .NET to open a text file and read
line-by-line e.g.

'open file
Dim sr As StreamReader
sr = File.OpenText("\My Documents\textdocument.txt")

'read a line
Dim row as String

row = sr.ReadLine()

'split a row into fields on the comma delimiter
Dim fields as String()

fields = row.Split(","c)

'continue reading rows

'close reader
sr.Close()


Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Ad

Advertisements

E

Ercan Turkarslan [MS]

Hi Adrian,

You can use a code similar to the one below. Actually this code should be
simpler than accessing the file from a data adapter.

Private Sub ReadTextFile(ByVal fileName As String)
Dim txtReader As StreamReader = New StreamReader(fileName)

Dim stInput As String
Dim seperators() As Char = {",", ".", vbTab, vbCrLf}

Do
stInput = txtReader.ReadLine()
If Not (stInput Is Nothing) Then
Dim subStrings() As String = stInput.Split(seperators)

' To do : Process the subStrings

End If
Loop Until stInput Is Nothing

txtReader.Close()
End Sub

Thanks

Ercan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top