Reading files into textbox

I need help with this little piece of code..am trying to read a file into a textbox.It is working with only some files.It is unable to show the characters of files like .exe,.bmp,... I want to create a text editor.(which should atleast open these sort of files).The code am using right now is..

' starts here... FILENAME is actually a filename as string with the whole path

Dim sr as new streamreader(FILENAME)

textbox1.text=sr.readtoend

sr.close

'Ends here..

Can someone help me?I even want to use the encoding stuff(but later)

Thanks anywayBig Smile

[673 byte] By [VijaySena] at [2007-12-16]
# 1
Why you would want anyone to be able to open an EXE file in a text editor is beyond me. If they change a single character then the whole executable is useless. Do you really want to risk that happening? It's the same situation with a bitmap. If they change one character then the whole image may be destroyed.
Also, remember that executables, etc. are binary files. The bytes of an EXE file do not represent ASCII or Unicode characters. When you use a StreamReader to open a binary file, it interprets the binary code as text, and therefore returns gibberish.
jmcilhinney at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Hi Vijay,

I agree with the answer already given. You may want to restrict the user from reading .EXE files. There is no practical use of being able to open a .EXE file in a texteditor.

Regards,
Vikram

Vikram at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
And unless you plan on showing a hex layout of the characters in the file, most exe's and other non text files have hidden characters that will not show up in a text box by reading the file directly.
Dustin_H at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
Vikram wrote:
Hi Vijay,

I agree with the answer already given. You may want to restrict the user from reading .EXE files. There is no practical use of being able to open a .EXE file in a texteditor.

Regards,
Vikram

Well did you ever try to open an exe in notepad?.It does open (though its gibberish).Then why would some company like microsoft be interested in doing so?Its the same with me, I want to display any file just like notepad.By the way i would like you to create a text box and read some files.Then you might know that only characters till some length are being displayed after that there is no display.It would be clear if you try this
Anyway Thankyou
(for sparing time for this)

VijaySena at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
While I am also puzzled as to why you'd want to do this, the code looks correct. However, if you have a single-line textbox, the characters may be "off-screen," as they are often not clumped together. Make sure your textbox's 'multiline' property is set to true.

bud1024 at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6
It's not clear why you'd want to display binary file content in a textbox, but assuming you have a good reason, then read on...

Streamreader is for reading text files. Your data may be munged if it contains null chars, etc..

If you want to read binary files, you can use one of these methods:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vagrfwritingtofileopenedforbinaryaccess.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconreadingwritingtonewlycreateddatafile.asp

Toddap at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...