When you use the
IO.File.ReadAllLines
method it returns an array of strings that are the lines in the file.
You are attempting to display an array of strings in the message box...but I think this will simply display something like
System.Array
and probably isn't crashing anything.
You are also attempting to do this:
- Dts.Variables("email_txt").Value = lines
Which is probably where you are having a problem. I am going assume that
Dts.Variables("email_txt")
is a TextBox....and I doubt that a TextBox has an
Value
property which is probably your issue.
You should change your code so that it knows that the type is a TextBox you can set it's Text Property.
Like this:
- DirectCast(Dts.Variables("email_txt"), TextBox).Text = lines
However, the above code will only display the first line in the array in the TextBox and you want to display the last 7.
Keeping in mind that the TextBox can only display 1 string, you will need to create a string with the appropriate content for it to display.
I recommend that you use the
http://msdn.microsoft.com/en-us/libr...gBuilder Class to help you with this.
Loop through your array backwards from the end 7 positions and add the line to the StringBuilder.
-
Dim sb As New StringBuilder
-
-
If lines.Count >= 7 Then
-
Dim linePosition As Integer= lines.Count - 1
-
Dim numLinesRead As Integer = 0
-
While numLinesRead < 7
-
sb.AppendLine(lines(linePosition))
-
linePosition -= 1
-
numLinesRead += 1
-
Loop
-
End If
Loop forwards through your array starting 7 positions back from the end and add the line to the StringBuilder.
-
Dim sb As New StringBuilder
-
-
If lines.Count >= 7 Then
-
Dim linePosition as Integer = lines.Count - 7
-
-
For linePosition To lines.Count - 1
-
sb.AppendLine(lines(linePosition))
-
Next
-
End If
Please note that none of the above code is tested ;)
-Frinny