Ken H.
asked on
Expression Help
If you follow my code below I have read all the lines in from the file already.
Now I need a way to collect just the preferred IP and hostnames from the data below. My thought was to check if the "PreferredFilerIPaddress" string exists in the file then grab the hostname(s) and ip(s) but I can't figure out how to do it.... i keep thinking loop but this is a single file so i don't think I'm on the right track.
[SYSTEM\CurrentControlSet\ Services\S WSvc\Param eters\Pref erredFiler IPAddresse s]
FAS250-NI1 10.10.1.201
FAS250-NI2 10.10.1.203
Now I need a way to collect just the preferred IP and hostnames from the data below. My thought was to check if the "PreferredFilerIPaddress" string exists in the file then grab the hostname(s) and ip(s) but I can't figure out how to do it.... i keep thinking loop but this is a single file so i don't think I'm on the right track.
[SYSTEM\CurrentControlSet\
FAS250-NI1 10.10.1.201
FAS250-NI2 10.10.1.203
Dim SDDATALOG As String = txtPath.Text & "\SnapDriveInfo\SnapDrive_RegistryInfo.log"
Dim SnapDriveData As String() = IO.File.ReadAllLines(SDDATALOG)
Dim prefFlrIP = From p In SnapDriveData Where p.Contains(txtHostName.Text) Select p.Substring(0)
Dim Row1 As DataRow
Try
Row1 = Table1.NewRow
Row1.Item(PrefIP) = If(prefFlrIP.Count > 0, prefFlrIP.FirstOrDefault, "Not Set")
Table1.Rows.Add(Row1)
Catch ex As Exception
End Try
Is these lines can appear multiple times in your file or only once ?
ASKER
these lines appear only once in the file, and i'm only reading from this one file.
So I'd use to good old way.
Dim firstLine As String = "[SYSTEM\CurrentControlSet\Services\SWSvc\Parameters\PreferredFilerIPAddresses]"
Dim lastLine As String = "[SYSTEM\CurrentControlSet\Services\SWSvc\Parameters\Protocols]"
Dim SDDATALOG As String = txtPath.Text & "\SnapDriveInfo\SnapDrive_RegistryInfo.log"
Dim SnapDriveData As String = IO.File.ReadAllText()
Dim myData As String = ""
Dim firstLinePos As Integer = SnapDriveData.indexOf(firstLine)
If firstLinePos <> -1 Then
firstLinePos += firstLine.Length
myData = SnapDriveData.Substring(firstLinePos, SnapDriveData.indexOf(lastLine ) - firstLinePos )
End If
ASKER
This doesn't seem to be grabbing any data. I even tried just output to a text box and it's blank.
Ideally I want this data in the table listed in the code.
Ideally I want this data in the table listed in the code.
If Directory.Exists(txtPath.Text & "\SnapDriveInfo\") Then
Dim SDVERLOG As String = txtPath.Text & "\SnapDriveInfo\SnapDriveVersionInfo.log"
Dim SDDATALOG As String = txtPath.Text & "\SnapDriveInfo\SnapDrive_RegistryInfo.log"
Dim firstLine As String = "[SYSTEM\CurrentControlSet\Services\SWSvc\Parameters\PreferredFilerIPAddresses]"
Dim lastLine As String = "[SYSTEM\CurrentControlSet\Services\SWSvc\Parameters\Protocols]"
Dim SnapDriveVersionInfo As String() = IO.File.ReadAllLines(SDVERLOG)
Dim SnapDriveData As String() = IO.File.ReadAllLines(SDDATALOG)
Dim SnapDriveData2 As String = IO.File.ReadAllText(SDDATALOG)
Dim myData As String = ""
Dim firstLinePos As Integer = SnapDriveData2.IndexOf(firstLine)
If firstLinePos <> -1 Then
firstLinePos += firstLine.Length
myData = SnapDriveData2.Substring(firstLinePos, SnapDriveData2.IndexOf(lastLine) - firstLinePos)
End If
Dim sdVersion As String = SnapDriveVersionInfo(16).Substring(93)
Dim sdService As String = SnapDriveData(20).Substring(26)
'Dim sdService = From p In SnapDriveData Where p.Contains("ObjectName") Select p.Split(" ").Last
Dim Row1 As DataRow
Try
Row1 = Table1.NewRow
Row1.Item(Version) = sdVersion
'Row1.Item(PrefIP) = If(myData.Count > 0, myData.FirstOrDefault, "Not Set")
Row1.Item(PrefIP) = myData
Row1.Item(ServiceAcct) = sdService
Table1.Rows.Add(Row1)
txtOut.Text = myData
Catch ex As Exception
End Try
Else
End If
Well.. Is the firstLine data really contained in the file ? Could you check if firstLine is found ? I mean to check the firstLinePos value. -1 meaning not found.
ASKER
I have attached the log file I'm pulling the data from.
The lines look like this:
[SYSTEM\CurrentControlSet\ Services\S WSvc\Param eters\Pref erredFiler IPAddresse s]
FAS250-NI1 10.10.1.201
FAS250-NI2 10.10.1.203
[SYSTEM\CurrentControlSet\ Services\S WSvc\Param eters\Prot ocols]
SnapDrive-RegistryInfo.log
The lines look like this:
[SYSTEM\CurrentControlSet\
FAS250-NI1 10.10.1.201
FAS250-NI2 10.10.1.203
[SYSTEM\CurrentControlSet\
SnapDrive-RegistryInfo.log
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The encoding on the file isn't unicode. I don't know why but none of the files I have to parse are unicode which makes things more difficult. Maybe I should be using a streamreader instead?
ASKER
This may be the action of last resort, i would have to open the file and save it to a temp directory in unicode format then open that file for reading.
I'm going to see if there is a way to do this with LINQ first.
Thank you for your effort in creating this solution for me!
I'm going to see if there is a way to do this with LINQ first.
Thank you for your effort in creating this solution for me!
If you know the encoding, the best would be to use it in the ReadAllX function you use.
Anyhow, to read it 100% correct, knowing the encoding is necessary.
Anyhow, to read it 100% correct, knowing the encoding is necessary.
ASKER
[SYSTEM\CurrentControlSet\
[SYSTEM\CurrentControlSet\