Page 1 of 1

using readalltext in visual studio

Posted: Tue Apr 18, 2006 3:44 pm
by Naethyn
I am trying to read a multiple line notepad document and display the text in a multiline text box.
Here is the code I am using:

Dim messageString As String = My.Computer.FileSystem.ReadAllText(c:\test123.txt).ToString
infoTextBox.Text = messageString

Unfortunatly if the notepad document has multiple lines it shows as a black square character at the end of each line. It then displays that black character in the text box instead of creating a new line. When I debug and step through the code and copy the black box from the messageString variable and then paste it into a text editor or even visual studio it creates a line!

Any help would be greatly appreciated.

Thanks,
Nathan

Posted: Tue Apr 18, 2006 3:50 pm
by Naethyn
Also,
The textvisualizer in debug mode can read the variable with mutliple lines. It doesnt solve the issue of writing it to a text box but it means the carriage control and line feed arent lost in the readalltext.

Posted: Tue Apr 18, 2006 4:05 pm
by Gidan
Translate every char into its ascii char value, then when it gets to the little black box, if its no the correct value for a carriage return, replace it. Probably wont work, but its worth a try.

Posted: Wed Apr 19, 2006 8:29 am
by Naethyn
I found out the problem.

The code above actually works. The reason I was having trouble is because I also tried to save the information to SQL server. After doing what you said, I noticed that the carriage returns where not being saved on SQL. Only the line feeds.

I found this code to add in the carriage returns after saving to a sql server. vbLf and vbCrLf are constants in vb.net

messageString = Replace(messageString, vbLf, vbCrLf)