Use BinaryReader to read the file. Then encode the byte array that is read from the file in base64 format, and assign a base64 encoded string in the text box
UPDATE:
A byte array that reads from a file can be encoded in a different text encoding before assigning a text field to display. Take a look at the following namespaces in the .net class, which are related to the character encoding format:
- System.Text.ASCIIEncoding
- System.Text.UTF8Encoding
- System.Text.UnicodeEncoding
- System.Text.UTF32Encoding
- System.Text.UTF7Encoding
Please make sure you know the exact encoding of the target file before converting from a byte array to an encoded string. Or you can check the bytes of the BOM file.
UPDATE (2):
Note that it is not possible to convert a non-text file (for example, an image file, a music file) using any of the System.Text classes. Otherwise, the value will not be displayed for the text box.
source share