• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

vb.net streamwriter.

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Crash893

"The man in black fled across the desert,
Joined
Mar 13, 2001
im makeing a small app to help me add entries to the hosts file in windows

i got most of it down except

when i
Code:
    Dim hostwriter As New StreamWriter("c:\hosts.txt")

            'Write line to hosts file
            hostwriter.WriteLine(vbNewLine & "127.0.0.1 ".PadRight(10) & TextBox1.Text.PadRight(5) & " #Blocked by Robert Barbrow")
            hostwriter.Close()

i know hosts insnt in c:\ its just a test file till i get it working


i get one line in the hosts file then it will over write that same line
how do i get streamwriter to read the lentgh of the file then increment it down one to add my entire?
 

Tacoman667

Member
Joined
Apr 28, 2001
Location
Kingwood, TX
If you wanted to put the new entry in the beginning of the file, you should do this:

Dim tString as string
Dim hostwriter As New System.IO.StreamWriter("c:\hosts.txt")

tstring = hostwriter.readall
hostwriter = New System.IO.StreamWriter("c:\hosts.txt")
hostwriter.WriteLine(tstring & vbNewLine & "127.0.0.1 ".PadRight(10) & TextBox1.Text.PadRight(5) & " #Blocked by Robert Barbrow")
hostwriter.Close()
 
OP
Crash893

Crash893

"The man in black fled across the desert,
Joined
Mar 13, 2001
thanks for your quick response

that extra ,true at the end works perfect