•      Powered by
 

Read a file and loop through the results using .NET 2.0 System.IO.Streamreader class

This technique I have found useful when needing to loop through a list of machines or other items.  This uses the System.IO.StreamReader namespace in .NET 2.0.  This is a simple example but can be used for connecting to remote machines, passing delimited information to another code function to perform some routine. 

One of the most useful examples I can provide is extracted information from SMS 2003.  SMS is another topic but is useful when needing to search various machines for specific information.  I use SMS to filter information and export to a delimited file.  I use this technique to loop the file and collect whatever information I am searching for.

 
    Sub Main()
        Dim reader As System.IO.StreamReader
        Dim line As String
        Try
            ' open a reader for the input file, and read line by line
            reader = New System.IO.StreamReader("niclist.txt")
            Do While reader.Peek() >= 0
                Try
                    line = reader.ReadLine()
                    Console.WriteLine(line)
                  Catch ex As Exception
                    Console.WriteLine(ex.ToString())
                End Try
            Loop
        Catch ex As Exception
            Console.Write(ex.ToString())
        End Try
    End Sub

 

tio

Terms of Use | Privacy Statement ©2005-2006 IISLogs.com. All rights reserved - Powered by IIS7 - info @ www.IIS.net