Append/Remove info in a txt file

laroberts

Active member
Joined
Jun 29, 2005
Messages
34
I am trying to figure out how to remove a line of text from a txt file from within VB.NET.

This is what my current code looks like, I put a line that says ***** where I know the delete command should go. I can not figure out how to do this. The item that I want to delete is contained with in JobFile


dim FILE_NAME as string = (String.format(H:\Operations\{0}\{1}\Master.txt", DayOfWeek, ShiftAssigned))
dim objwriter as new system.io.streamwriter(FILE_NAME, true)
dim jobfile as string = CStr(Me.ComboBox3.SelectedItem)

***** The delete command should go here!!!*****


Beep()
MsgBox("Master List Updated.")



Thank you!!!
 
Youll want to read the entire text file into a string variable, delete the line of text from the string variable, then, overwrite the textfile with a new textfile (same name) that contains that string that you just edited.
 
Read the file in using a StreamReader. You can read the whole file in one go using ReadToEnd, or line by line using ReadLine. Once you have a String variable or array, you can simply replace the appropriate line using whatever type of string manipulation seems most appropriate. Finally, write the file back out again using a StreamWriter.
 
Back
Top