Solved

Open as text

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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 …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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