Solved

Open as text

Posted on 2006-07-15
4
212 Views
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?

Cheers,

Tom
0
Comment
Question by:TommyTwoPints
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:Sancler
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.

Roger
0
 
LVL 3

Author Comment

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

Thankyou very much,

Tom
0
 
LVL 3

Author Comment

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

Accepted Solution

by:
Sancler earned 500 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
        OpenFileDialog1.ShowDialog()
        Dim filename As String = OpenFileDialog1.FileName
        Dim sr As New StreamReader(filename)
        Dim s As String = sr.ReadToEnd
        sr.Close()
        Dim displaytext As String = s.Replace(Chr(0), Chr(126)) ' replaces Null with ~
        RichTextBox1.Text = displaytext
    End Sub

Roger
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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