Wednesday, December 15, 2010

VB.NET Insert into TEXT File

Imports System.IO

Dim FILENAME As String = Server.MapPath("IP.txt")
                          OR
Dim FILENAME As String = "c:\IP.txt"

            Dim objStreamWriter As StreamWriter
            objStreamWriter = File.AppendText(FILENAME)
            objStreamWriter.WriteLine("External ip :" & externalip)
            objStreamWriter.WriteLine("Local ip    :" & localipaddresses)
            objStreamWriter.WriteLine("Remote ip   :" & strip)
            objStreamWriter.WriteLine("DateTime    :" & DateTime.Now)
            objStreamWriter.WriteLine("----------------------------------")
            objStreamWriter.Close()
            Dim objStreamReader As StreamReader
            objStreamReader = File.OpenText(FILENAME)
            Dim contents As String = objStreamReader.ReadToEnd()
            objStreamReader.Close()

No comments: