Open as text

Posted on 2006-07-15
Medium Priority
Last Modified: 2010-04-23
Hi Experts,

I have a problem i can get my head around.

With Notepad.exe you can open any file type as text. When i try to replicate this using streams it doesnt work.

I only shows about 5 of the characters.

How would i be able to to achieve this?


Question by:TommyTwoPints
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 34

Expert Comment

ID: 17115517
What are you trying to replicate it in?  Most of the controls that display text in VB.NET - e.g textbox, messagebox, label - stop reading as soon as they encounter a Null - Chr(0).  Non-text files usually have lots of those in them.  You will probably have to use a .Replace of some sort to change any Nulls to something else before you can display it.


Author Comment

ID: 17115521
Ok, i was trying to display it in a richtextbox.

Thankyou very much,


Author Comment

ID: 17115541
when i read the stream using a streamreader, it only gets the first few characters when using the readtoend function.
LVL 34

Accepted Solution

Sancler earned 2000 total points
ID: 17115986
Try this.  Imports System.IO.  One form. One button.  One OpenFileDialog.  One RichTextBox.  

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim filename As String = OpenFileDialog1.FileName
        Dim sr As New StreamReader(filename)
        Dim s As String = sr.ReadToEnd
        Dim displaytext As String = s.Replace(Chr(0), Chr(126)) ' replaces Null with ~
        RichTextBox1.Text = displaytext
    End Sub


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question