Solved

Open as text

Posted on 2006-07-15
4
209 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now