Reading and writing text files is an essential task in any programming language. Follow this step-by-step approach to working with text files in VB .NET.

Years ago, when I first learned to program in BASIC, I came across a sample program for reading a text file. The OPEN command with the file number looked quite confusing, so I never wrote the program. Later, when I learned Visual Basic, I was shocked to see that the same file operations existed in VB. The basic file-handling commands had not changed; just a few more features had been added.

With Visual Basic .NET, Microsoft introduced a new, object-oriented method for working with files. The System.IO namespace in the .NET framework provides several classes for working with text files, binary files, directories, and byte streams. I will look specifically at working with text files using classes from the System.IO namespace.

Basic methods
Before we jump into working with text files, we need to create a new file or open an existing one. That requires the System.IO.File class. This class contains methods for many common file operations, including copying, deleting, file attribute manipulation, and file existence. For our text file work, we will use the CreateText and OpenText methods.

WEEKLY .NET HOW-TOS

New .NET tutorials updated every Thusday with Cast Your .NET

CreateText
True to its name, the CreateText method creates a text file and returns a System.IO.StreamWriter object. With the StreamWriter object, you can then write to the file. The following code demonstrates how to create a text file:
Dim oFile as System.IO.File
Dim oWrite as System.IO.StreamWriter
oWrite = oFile.CreateText(“C:\sample.txt”)
OpenText

The OpenText method opens an existing text file for reading and returns a System.IO.StreamReader object. With the StreamReader object, you can then read the file. Let’s see how to open a text file for reading:
Dim oFile as System.IO.File
Dim oRead as System.IO.StreamReader
oRead = oFile.OpenText(“C:\sample.txt”)
Writing to a text file

The methods in the System.IO.StreamWriter class for writing to the text file are Write and WriteLine. The difference between these methods is that the WriteLine method appends a newline character at the end of the line while the Write method does not. Both of these methods are overloaded to write various data types and to write formatted text to the file. The following example demonstrates how to use the WriteLine method:
oWrite.WriteLine(“Write a line to the file”)
oWrite.WriteLine()         ‘Write a blank line to the file
Formatting the output

The Write and WriteLine methods both support formatting of text during output. The ability to format the output has been significantly improved over previous versions of Visual Basic. There are several overloaded methods for producing formatted text. Let’s look at one of these methods:
oWrite.WriteLine(“{0,10}{1,10}{2,25}”, “Date”, “Time”, “Price”)
oWrite.WriteLine(“{0,10:dd MMMM}{0,10:hh:mm tt}{1,25:C}”, Now(), 13455.33)
oWrite.Close()

The overloaded method used in these examples accepts a string to be formatted and then a parameter array of values to be used in the formatted string. Let’s look at both lines more carefully.

The first line writes a header for our report. Notice the first string in this line is {0,10}{1,10}{2,25}. Each curly brace set consists of two numbers. The first number is the index of the item to be displayed in the parameter array. (Notice that the parameter array is zero based.) The second number represents the size of the field in which the parameter will be printed. Alignment of the field can also be defined; positive values are left aligned and negative values are right aligned.

The second line demonstrates how to format values of various data types. The first field is defined as {0,10:dd MMMM}. This will output today’s date (retrieved using the Now() function) in the format 02 July. The second field will output the current time formatted as 02:15 PM. The third field will format the value 13455.33 into the currency format as defined on the local machine. So if the local machine were set for U.S. Dollars, the value would be formatted as $13,455.33.

Listing A shows the output of our sample code.

Listing A

   Date         Time                   Price
   22 July     10:58 AM           $13,455.33


Reading from a text file
The System.IO.StreamReader class supports several methods for reading text files and offers a way of determining whether you are at the end of the file that's different from previous versions of Visual Basic.

Line-by-line
Reading a text file line-by-line is straightforward. We can read each line with a ReadLine method. To determine whether we have reached the end of the file, we call the Peek method of the StreamReader object. The Peek method reads the next character in the file without changing the place that we are currently reading. If we have reached the end of the file, Peek returns -1. Listing B provides an example for reading a file line-by-line until the end of the file.

Listing B

oRead = oFile.OpenText(-C:\sample.txt")

 While oRead.Peek <> -1
       LineIn = oRead.ReadLine()

 End While

 oRead.Close()


An entire file
You can also read an entire text file from the current position to the end of the file by using the ReadToEnd method, as shown in the following code snippet:
Dim EntireFile as String
oRead = oFile.OpenText(“C:\sample.txt”)
EntireFile = oRead.ReadToEnd()

This example reads the file into the variable EntireFile. Since reading an entire file can mean reading a large amount of data, be sure that the string can handle that much data.

One character at a time
If you need to read the file a character at a time, you can use the Read method. This method returns the integer character value of each character read. Listing C demonstrates how to use the Read method.

Listing C

Dim intSingleChar as Integer

 Dim cSingleChar as String

 oRead = oFile.OpenText(-C:\sample.txt")

 While oRead.Peek <> -1

 intSingleChar = oRead.Read()

 ' Convert the integer value into a character

 cSingleChar = Chr(intSingleChar)

 End While

Tap into the power
We've barely scratched the surface of the new file functionality included in .NET, but at least you have an idea of the power now available in the latest edition of Visual Basic .The abilities of the classes in the System.IO namespace are quite useful, but if you want to continue to use the traditional Visual Basic file operations, those are still supported.

Do you need help with Windows? Gain advice from Builder AU forums

Related links

Comments

1

soma - 13/07/04

also provides some codes for reading the text line by line.

» Report offensive content

2

nick - 19/02/05

wow this is great ivebenn looking for this code for ages

» Report offensive content

3

Ted Tomany - 07/05/05

Very informative article. Helps me a lot.

» Report offensive content

4

Howard Simon - 10/05/05

First of all, thanks for taking the time to place pieces of code on the internet such that people like myself can use other's knowledge to program. However, I am running into a problem. This method, along with the Print #1, allowed within VB in Excel macros is limited to ~32K size. What method can be used in an Excel macro environment that would exceed the 32K limitation?

» Report offensive content

5

asdf - 11/05/05

This has been a great help. However how do you "attempt" to read from a file. In other words how do you handle an exception when no file can be found?

Say if i want to open a file called "asdf.txt" but only if it exsists. If I try and do it with your code my program just crashes if it doesn't exist.

» Report offensive content

6

Andrew Kong - 15/11/05

I find your articles really helpful but I am trying to find out some more info about this readline() method...

I want to open a text file and search for a specific character in my case a "=". I also want to see if there is a string of characters beyond the =. The text file has many lines some with characters beyond the "=" some without...I want to count the amount of lines with characters beyond the "="

If you can help it would be greatly appreciated

» Report offensive content

7

Hany Mousatfa Khodair - 17/11/05

That was really helpfull and mostry Focused
Thank you very much

» Report offensive content

8

Gourisankara - 18/11/05

Hi every body,
i am developing VB.det post, how to call .txt file in my application.I tried this way but i didn't get the answer.
This is my code:
Dim EntireFile As String
read = File.OpenText("D:\sample.txt")
EntireFile = Read.ReadToEnd()

» Report offensive content

9

Harsha Vardhan - 01/12/05

sir i want full code in a sequential wise how to read n write a text file in vb.net as a beginner of vb.net

» Report offensive content

10

Barbara JoAn Varner - 30/01/06

your informatin is very informative as far as it goes. i have many more issues to solve
Attaching sublists to selected nodes of the main list. there are two text files each with data for the same players, 15 of them one is current data the other is history scores for from 3 to 10 years. I need to read both files and combine the data for each player and write it to a file sorted by year.
Building an ordered list (each sublist will be an ordered list)
Sorting a linked list (the main list will be sorted)
Building a doublely-linked list
Functionality to interactively add payer nodes
Functionality to edit and delete player data
Searching a linked list
Opening an external file for output and writing to the file
any ideas?

» Report offensive content

11

Rose Anne Coulter - 04/02/06

Excellent web site. Simple and easy to use. A bookmark I will keep.

» Report offensive content

12

praneth raj - 18/04/06

If i store data in text files in 3 different columns and i want to retreive data form a particular column. How is it possible to traverse along one particular column until it ends
Please reply i am in nedd of that

» Report offensive content

13

Bob man - 12/06/06

I to would like some info on how to get info from 3 columns. please email thanks

» Report offensive content

14

Brice - 12/07/06

great tut boys

<input type="text" />

» Report offensive content

15

vijay - 14/07/06

Dear Sir,
i want to read a text file line by line and at the same moment
i want each line to be written in new file,i.e i want to copy file line by line and want to give the new file name as older one
please help me

regards
vijay

» Report offensive content

16

Chaitra - 18/07/06

Hello,

Thank you very much for this code... It really works great.
However, I want to read only last line of the .txt file.

Is that possible???

REgards
Chaitra

» Report offensive content

17

sangeeta - 19/07/06

How do you search for files and folders mathing the string input by a given user in the textbox in vb .net?

» Report offensive content

18

Cory Sharshel - 28/07/06

Does anyone know if it is possible to read a file line by line starting at the end of the file and working towards the start of the file?

Regards

» Report offensive content

19

Mohan Kumar - 03/08/06

I Want to print a text file using with VB.Net (for Dot Matrix Printing)
and
How to set a right alignment in a text file?

» Report offensive content

20

Baseer - 03/08/06

i would like to Read a text file line by line and at the same moment write to it line by line? is it possible to do it without creating temp text files.. ?

» Report offensive content

21

Muktesh Shrivastav - 11/08/06

hi,
I want read a text file and search for a particular pattern appearing in it. using vb.net.
if it is possible please provide some code also for it

regards
muktesh

» Report offensive content

22

sanjay - 18/08/06

i want to change the font of text that i passed in writeline method ..
please do help

» Report offensive content

23

Balakrishnan - 26/08/06

Hi tis very nice..
i want 2 know if the file is existing means i want to append the file..
how can do tis..

» Report offensive content

24

Puneet - 29/08/06

its helpful
plz explain my code also
bw.Write(CStr(j))
what this line represents

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fstream As New filestream("c:\mylog.txt", filemode.openorcreate, fileaccess.readwrite)
Dim bw As BinaryWriter = New BinaryWriter(fstream)
Dim br As BinaryReader = New BinaryReader(fstream)
Dim j As Integer
For j = 1 To 5
bw.Write(CStr(j))
Next
br.BaseStream.Seek(0, SeekOrigin.Begin)
textbox1.text = br.ReadChars(10

» Report offensive content

25

dks - 29/08/06

to run a bat file using vb.net

» Report offensive content

26

oms - 14/09/06

how to copy inputs from GUI calculator to exe file of bc commands...means how to copy integer calculations to bc.exe command prompt to calculate with the bc commands...
first things is to open the exe file and then auto copy that integers to the exe file and auto calculate..

I have writed some code to link the exe file..
but don't know how to copy that integers into the exe file...
and also don't know how to auto display characters in the sub directory folder...
I must display like...
eg..c:\bc_code>.\echo 4+3 |bc
7 <- is auto display
then copy that display 7 into the GUI again...
so, could anybody help my problem please...???

Dim startInfo As New ProcessStartInfo("C:\Windows\system32\cmd.exe")
startInfo.WorkingDirectory = "c:\bc_code"

» Report offensive content

27

aruna - 21/09/06

hello sir
can u plz suggest me how to open a form in a text file

» Report offensive content

28

Kamlesh Gujarathi - 27/09/06

Easy way is to read the file is only in VB.NET is -

objFile = objFile.OpenText(“C:\MyFile.txt”)
While objFile.Peek <> -1
objFile.Read()
End While

Thanks

Kamlesh Gujarathi (TL)
ITShastra INDIA Pvt Ltd.
kamleshvgujarathi@yahoo.com

» Report offensive content

29

Joe - 27/09/06

this is the best way that I have found to read and write to a file...

Imports System.IO
'NameSpace required to be imported to work with files
Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Read.Click
Dim fs As New FileStream("sample.txt", FileMode.Open, FileAccess.Read)
'declaring a FileStream to open the file named file.doc with access mode of reading

TextBox1.Text = ""
Dim d As New StreamReader(fs)
'creating a new StreamReader and passing the filestream object fs as argument
d.BaseStream.Seek(0, SeekOrigin.Begin)
'Seek method is used to move the cursor to different positions in a file, in this code, to
'the beginning
While d.Peek() > -1
'peek method of StreamReader object tells how much more data is left in the file
TextBox1.Text &= d.ReadLine()
'displaying text from doc file in the RichTextBox
End While
d.Close()

End Sub

Private Sub write_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles write.Click
Dim fs As New FileStream("sample.txt", FileMode.Open, FileAccess.Write)
'declaring a FileStream and open a document file named file with
'access mode of writing
Dim s As New StreamWriter(fs)
'creating a new StreamWriter and passing the filestream object fs as argument
s.WriteLine("This is an example of using file handling concepts in VB .NET.")
s.WriteLine("This concept is interesting.")
'writing text to the newly created file
s.Close()
'closing the file
End Sub
End Class

» Report offensive content

30

Joe - 27/09/06

this is the best way that I have found to read and write to a file...

Imports System.IO
'NameSpace required to be imported to work with files
Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Read.Click
Dim fs As New FileStream("sample.txt", FileMode.Open, FileAccess.Read)
'declaring a FileStream to open the file named file.doc with access mode of reading

TextBox1.Text = ""
Dim d As New StreamReader(fs)
'creating a new StreamReader and passing the filestream object fs as argument
d.BaseStream.Seek(0, SeekOrigin.Begin)
'Seek method is used to move the cursor to different positions in a file, in this code, to
'the beginning
While d.Peek() > -1
'peek method of StreamReader object tells how much more data is left in the file
TextBox1.Text &= d.ReadLine()
'displaying text from doc file in the RichTextBox
End While
d.Close()

End Sub

Private Sub write_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles write.Click
Dim fs As New FileStream("sample.txt", FileMode.Open, FileAccess.Write)
'declaring a FileStream and open a document file named file with
'access mode of writing
Dim s As New StreamWriter(fs)
'creating a new StreamWriter and passing the filestream object fs as argument
s.WriteLine("This is an example of using file handling concepts in VB .NET.")
s.WriteLine("This concept is interesting.")
'writing text to the newly created file
s.Close()
'closing the file
End Sub
End Class

» Report offensive content

31

priyantha - 17/10/06

does anyone know about designing the link list to store text masages which from text file of through users (using vb.net)

» Report offensive content

32

Kaleem - 30/10/06

Friends,

I am developing software for Smart Device using VB.NET, I have a text file of 45 MB. When I search record it takes long time as I am using loop. I want to know how to create index to a text file and seek using Index which will give fast search.

Thanks in Advance.

» Report offensive content

33

Kaleem - 30/10/06

Friends,

I am developing software for Smart Device using VB.NET, I have a text file of 45 MB. When I search record it takes long time as I am using loop. I want to know how to create index to a text file and seek using Index which will give fast search.

Thanks in Advance.

» Report offensive content

34

Pankaj Sisodiya - 31/10/06

35

JNorte - 05/11/06

To read last line i use this, and it work's for me.


Public Shared Function ReadLastLine(ByVal path As String) As String
Dim retval As String = ""
Dim fs As FileStream = New FileStream(path, FileMode.Open)

Dim pos As Long = fs.Length - 2
While pos > 0

fs.Seek(pos, SeekOrigin.Begin)
Dim ts As StreamReader = New StreamReader(fs)

retval = ts.ReadToEnd
Dim eol As Integer = retval.IndexOf("" & Microsoft.VisualBasic.Chr(10) & "")
If eol >= 0 Then
fs.Close()
Return retval.Substring(eol + 1)
End If
System.Threading.Interlocked.Decrement(pos)
End While
fs.Close()
Return retval
End Function

» Report offensive content

36

zoma - 07/11/06

pls sir,

can anyone give me a sample login code using usrename and password that willl be able to access files instead of database,add new users to the text file and for new users to be able to sign in, generally reading and writing to a text file but using forms instead of a console application.

regards

» Report offensive content

37

krishna - 09/11/06

how to read a .upd file and display it in textbox using vb.net.if file is random access mode

» Report offensive content

38

Sandeep - 12/11/06

39

priyantha - 13/11/06

i want to know about create link list and how it will defrag and graphically represent the defragment process using grid.

» Report offensive content

40

Manoj Kumar - 15/11/06

any one help me to store every line of the text file into an array and to display it on RichTetBox control and any ideas on arranging the contents in alphabetical order.

Thanks in Advance.

» Report offensive content

41

kumar nitya nand - 22/11/06

This code may helps you all to read and write the file

Imports System.IO


Public Function GetFileContents(ByVal FullPath As String, _
Optional ByRef ErrInfo As String = "") As String

Dim strContents As String
Dim objReader As StreamReader
Try

objReader = New StreamReader(FullPath)
strContents = objReader.ReadToEnd()
objReader.Close()
Return strContents
Catch Ex As Exception
ErrInfo = Ex.Message
End Try
End Function

Public Function SaveTextToFile(ByVal strData As String, _
ByVal FullPath As String, _
Optional ByVal ErrInfo As String = "") As Boolean

Dim Contents As String
Dim bAns As Boolean = False
Dim objReader As StreamWriter
Try


objReader = New StreamWriter(FullPath)
objReader.Write(strData)
objReader.Close()
bAns = True
Catch Ex As Exception
ErrInfo = Ex.Message

End Try
Return bAns
End Function

» Report offensive content

42

Balakrishnan - 11/12/06

I want to search the particulare string in text file and change the string to another string.

» Report offensive content

43

Somasundaram - 10/01/07

How to get the .Doc file's contents Using VB.net...

I want to get the .txt and .Doc files. but here i wrote the code only for displaying the txt file's contents.But it wont display the .Doc files.

I select the Doc and txt fileNames in Listbox.but File's Contents has to display in Richtextbox.

so I've written the code for(.txt) files only.But i need (.Doc) file's contents also.So How to get the (.Doc files Contents).So pls some one Help me......

Private Sub ListBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox3.SelectedIndexChanged

Dim myFile As System.IO.FileInfo
Dim fileInfo As String
Dim myFileName As String
Dim stream As StreamReader
Dim input As String

myFileName = ListBox3.SelectedItem.ToString
myFile = New System.IO.FileInfo(fileName:=myFileName)
fileInfo = myFileName.Length.ToString
stream = File.OpenText(myFileName)
input = stream.ReadLine()
Console.WriteLine(input)
RichTextBox1.Text = input
stream.Close()
End Sub


» Report offensive content

44

somasundaram - 10/01/07

How to get the .Doc file's contents Using VB.net...

I want to get the .txt and .Doc files. but here i wrote the code only for displaying the txt file's contents.But it wont display the .Doc files.

I select the Doc and txt fileNames in Listbox.but File's Contents has to display in Richtextbox.

so I've written the code for(.txt) files only.But i need (.Doc) file's contents also.So How to get the (.Doc files Contents).So pls some one Help me......

Dim myFile As System.IO.FileInfo
Dim fileInfo As String
Dim myFileName As String
Dim stream As StreamReader
Dim input As String

myFileName = ListBox3.SelectedItem.ToString
myFile = New System.IO.FileInfo(fileName:=myFileName)
fileInfo = myFileName.Length.ToString
stream = File.OpenText(myFileName)
input = stream.ReadLine()
Console.WriteLine(input)
RichTextBox1.Text = input
stream.Close()
End Sub

» Report offensive content

45

Teddy - 26/01/07

Can some one help how to access recent documents in vb.net
I have menu- with open, save , I want to see recent saved documents

» Report offensive content

46

manisha - 01/03/07

sir,

i wanted to store selected items of listbox in the file.
how to write(store) it in file i am not geting? Please guide me.


Thanks,
Manisha

» Report offensive content

47

Manisha - 02/03/07

please guide me for how to write data in a file.



Thanks,
Manisha

» Report offensive content

48

Sanjay - 05/03/07

Please Can anyone help regarding file handling querry is
how can i change font size while writing into word document with writeline method ....
Please help

» Report offensive content

49

Kishor A. Jagtap - 06/03/07

I want to Genrate a text File From the form

» Report offensive content

50

Jan Laureys - 14/03/07

Thanks for the info :)

» Report offensive content

51

dk - 30/03/07

Hello Sir

I am new in vb.net and i am working on reading and writing files project i have done how to write text in file and now i also want to display file text in message box or in different form like i stored name and age in one line and second line is name2 and age2 and so on ..and i put one combo box so it's displays all the name which already saved in test.txt file
now what i want to do here if user choose one name from combo box so i want to display only that name and age not anyother name and age in that test.txt file i mean if user choose name5 from combo box so i want to display name5 and age5 in message box or in text box

any help

wating for your kind rep.

» Report offensive content

52

Himanshu Anand - 02/04/07

i want to access a file(web.config) but i want to access some perticular values from that file, not the whole file.
So how can i serach for a keyword in whole file.
Apart from this i have to show these key word in a data grid.
Can anyone help me in doing this.

Any type of help will be highly appriciated.

Thanks in advance.
Himanshu.

» Report offensive content

53

Neeraj Kumar - 05/04/07

Hi
I wants to change the font size in text report.
But not able to do so.
Plz help me.

Thanks

» Report offensive content

54

aisya - 12/04/07

Could you please to tell me how to save data sql server to the text files....if you dont mind ...give samples code to import data from sql server and saves it at text files.... please...these my code
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
phoneStreamWriter.WriteLine(txtName.Text)
phoneStreamWriter.WriteLine(txtPhone.Text)
With txtName
.Clear()
.Focus()
End With
txtPhone.Clear()
End Sub

» Report offensive content

55

Sunitha - 17/04/07

Thnak a lot for this infomation.

» Report offensive content

56

Sunitha - 20/04/07

Some code to hep you for writing into a file.

Imports System.IO
'NameSpace required to be imported to work with files
Public Class Form1 Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles MyBase.Load
Dim fs as New FileStream("file.doc", FileMode.Create, FileAccess.Write)
'declaring a FileStream and creating a word document file named file with
'access mode of writing
Dim s as new StreamWriter(fs)
'creating a new StreamWriter and passing the filestream object fs as argument
s.BaseStream.Seek(0,SeekOrigin.End)
'the seek method is used to move the cursor to next position to avoid text to be
'overwritten
s.WriteLine("This is an example of using file handling concepts in VB .NET.")
s.WriteLine("This concept is interesting.")
'writing text to the newly created file
s.Close()
'closing the file
End Sub
End Class

» Report offensive content

57

Mark Jones - 23/04/07

Excellent, just what I was looking for

» Report offensive content

58

Ravfee - 23/04/07

thank for infomation

» Report offensive content

59

Raheem MA - 01/06/07

Great explanation about files concept for beginers of VB.Net. It helps me alot.

thanks for ur help.

» Report offensive content

60

Raheem MA - 01/06/07

Great Explanation, It helps alot for Beginers of VB.Net like me.


thanks ...

» Report offensive content

61

Vijay - 08/06/07

Thanks for the good stuff.!!

» Report offensive content

62

Satish - 08/06/07

good information

» Report offensive content

63

Ravikiran - 18/06/07

hi,

i wanted to know how to write in a text.txt file in a particular position i want fix the containt in a particular position as i want

» Report offensive content

64

Surbhi - 20/06/07

I need a code in VB which will read the .txt file and replace no. of spaces with one comma and then this file will be opened in excelsheet where at encounter of each comma the column will change.

Pls help me....!!!!

» Report offensive content

65

Ayaz Khan - 25/06/07

I need to read data from a text file and insert them into a table with the column provided in the text file. Please help me with this. Ayaz

» Report offensive content

66

Raj - 17/07/07

Thanks for the info :)..Its very use full

» Report offensive content

67

prabhat - 21/08/07

How to convert the readonly mode of a file to append mode??


is it possible??
plz help me.

» Report offensive content

68

prabhat - 21/08/07

How to convert the readonly mode of a file to append mode??


is it possible??
plz help me.

» Report offensive content

69

Shehan - 24/08/07

Thank you! This helped me a lot!

» Report offensive content

70

Shehan - 24/08/07

Thank you! This helped me a lot!

» Report offensive content

71

sikhan - 30/08/07

I am new in VB.Net codding, i have a project to read the particular folder in that folder have files to search n which will open in txt file in list box or txt box and search some data i.e. filename etc which will show in grid
( which is came through novel server)

so please help me regarding this and if you have infromation about please forward to my email address sikhan555@yahoo.com.

thanks in advance

regards

sikhan

» Report offensive content

72

sikhan - 30/08/07

I am new in VB.Net codding, i have a project to read the particular folder in that folder have files to search n which will open in txt file in list box or txt box and search some data i.e. filename etc which will show in grid
( which is came through novel server)

so please help me regarding this and if you have infromation about please forward to my email address sikhan555@yahoo.com.

thanks in advance

regards

sikhan

» Report offensive content

73

sonal - 08/10/07

Really very Useful

hi
how to store all (text files,images,document,mdb,xml)in sql server 2005 database in vb.net?

» Report offensive content

74

Chloe - 09/11/07

Hi all,

i am working on a project that read the database file from Access in VB.NET. Then I have to chop a original data from the column and fill the splitted data into new column.
For example, the data in the particular column is
ABC 1 2 1

So i have to split the numbers by ignoring the characters and assign it into new column. It's huge data.
Anyone could help?
Thanks in advance.

» Report offensive content

75

Jaya - 26/11/07

As I am a fresher in vb.net, i want to know how text reports can be created in this. And how values can be taken from the database?

» Report offensive content

76

Johnny - 05/12/07

Hey All I'm a begginer at vb.net all i wan't to know is how would I store some information from a simple combo box in a textfile or put the contents of the combobox into a .txt file if anybody can help
thanks

» Report offensive content

77

asrol - 17/01/08

How to delete specific data in text file ? Any body help me.

» Report offensive content

78

Nilesh(TigerN*) - 19/02/08

first i have Thanking you.
for help me in spliting.

» Report offensive content

79

tushar - 05/03/08

can we do this file creatino and writing in C# .NET

» Report offensive content

80

sharath - 12/03/08

can we use loops in writting a Line

» Report offensive content

81

jubertroldan - 26/03/08

i need help in replacing a specified line (with index) in a text file. please help. jubertroldan@yahoo.com thankyou

» Report offensive content

82

jerrychu - 30/03/08

Say, i got a txt file, the value inside is copy from excel. like
1 2
1 3
1 5
I got 100k lines record, I want to do some calculations, so I want to define a(i) for first colonum and b(i) for second column. so how should I do it? Thanks

» Report offensive content

83

John Madison - 02/04/08

Imports System
Imports System.IO

Dim oFile as System.IO.File
Dim oWrite as System.IO.StreamWriter
oWrite = oFile.CreateText(“C:\sample.txtâ€)
OpenText

The "oWrite = oFile.CreateText..." line gives me the error:
"Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated."

What am I doing wrong? I can never get VB.NET examples to work. Even the simple ones. It always seems that some vital peice of information gets left out.

Though at least this example mentioned the IMPORTS statement. Sometimes examples leave out what to import. Which makes it very confusing for someone who only programs in their spare time.

» Report offensive content

84

chandru - 02/04/08

how to read a particular line in the text file.
if anybody knows help me.

thanks,
chandru

» Report offensive content

85

pcpchandru - 02/04/08

how to read a particular line in the text file using vb.net 2005
if anybody knows help me.

thanks,
chandru

» Report offensive content

86

pcpchandru - 02/04/08

you have to create a file using filestream then onlt u will write a string on the particular file name.

Dim FStream1 As IO.FileStream = New IO.FileStream("C:\testfile.txt", IO.FileMode.Append, IO.FileAccess.Write)
Dim SWriter1 As IO.StreamWriter = New IO.StreamWriter(FStream1)
SWriter1.Write("**********")
SWriter1.Close()
FStream1.Close()


use the above code .

» Report offensive content

87

James - 10/04/08

How do I read a text file and have it display line by line in VB.Net or show only certain lines like only show line 3 or 4

» Report offensive content

88

syam - 11/05/08

can you specify
best way to operate on files
both binary and text file
which are the main class to use

» Report offensive content

89

aseem - 12/05/08

i am trying to do doing programs in pocket pc device windows ce os how i can make tab controls and data reading possible in this device

» Report offensive content

90

sruthi.c - 14/05/08

how to read and dispaly any type of file say .doc,pdf,excelspreadsheet in a textbox in c# windowsforms

i am able to read and dispaly only text files not not the other file.
Please help.

» Report offensive content

91

stephen - 05/06/08

How can i read from text file one line at a time? I'm implementing a next and previous button which will only retrieve a single line everytime a button is pressed.. thank you..

» Report offensive content

92

stephen - 05/06/08

How can i read from text file one line at a time? I'm implementing a next and previous button which will only retrieve a single line everytime a button is pressed.. thank you..

» Report offensive content

93

Rajendra prasad - 09/07/08

How to search a file or folder when i give a input in textbox control that should be search Entire Drive and display the Actual path where it is located I am doing this Application in C#.net windows applicaion plz help me

» Report offensive content

94

wahid ali - 10/09/08

your code is not help me.


i want there is .txt file in my system.open the .txt it having white spaces.i want some text in a column till last row and comes into database.

» Report offensive content

95

aneroph - 15/09/08

None of these methods are working for me. i have been looking all over to figure out how to read and write in VB 2008 but i cant find a single tutorial that works. I am making a game and i want to be able to save high scores and names to a file and then when someone plays through i need to open up that file and compare their score with the other numbers saved and possibly insert it. i can do the "if" statements and what not but i cant find anything that works even to just save some text let alone ten different texts with names. someone please help

» Report offensive content

96

Rosh - 24/09/08

Hey,
None of the Codes are working for me.
Im new to VB.Net working on Win App.s.(VS-2005) Im tryuing to read a text file and display the contents in the text items of the App. form.

Can any one plz help.

» Report offensive content

97

Nader Hussain - 03/10/08

How do I define oFile? The object must be assigned a value. This is for a *.txt file.

» Report offensive content

98

Rozie - 08/10/08

How can i convert from vnet to text file..
please help...

thans..

» Report offensive content

99

vishals - 02/11/08

Hi I need help. I am having difficulty in reading and writing data from datagrid in vb.net from text files.
I have to first write the data entered to the text files.
and secondly to call same on the datagrid.

Thanks to advise the code.

» Report offensive content

100

Mironi - 14/11/08

Thanks for taking your time to help me and others.
These comments and codes helped me.

» Report offensive content

101

1 - 15/11/08

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

101

1 - 15/11/08

3 ... more

100

Mironi - 14/11/08

Thanks for taking your time to help me and others. These comments and codes helped me. ... more

99

vishals - 11/02/08

Hi I need help. I am having difficulty in reading and writing data from datagrid in vb.net from text files. I have ... more

Log in


Sign up | Forgot your password?

What's on?