Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Open as text

Posted on 2006-07-15
4
Medium Priority
?
217 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
[X]
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
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 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
        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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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 …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

636 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