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 anyway
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.
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)
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.