Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,207,682 members, 7,999,929 topics. Date: Monday, 11 November 2024 at 04:55 PM

How Can I Attach A Text File To A VB.NET Program - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Can I Attach A Text File To A VB.NET Program (2770 Views)

Generating Crystal Report With MYSQL Database For A VB.NET Application / Genrating Crystal Report With Mysql Database In A Vb.net Application / How Do I Attach My Ajax Toolkit With Visual Studio (2) (3) (4)

(1) (Reply) (Go Down)

How Can I Attach A Text File To A VB.NET Program by Lakulos(m): 9:53pm On Nov 12, 2012
Please i want a open text file stored on my documents in a RichTexBox in my program

Here is my code:

private sub openToolStripMenuItem click(ByVal...........)

Dim file as string
OpenFileDialog1.Title="open a file"
OpenFileDialog1.InitialDirectory="C:\"
OpenFileDialog1.Filter="Text file|*.txt"
OpenFileDialog1.show()
file=OpenFileDialog1.FileName
RichTextBox1.Text=

This is where i got stuck. Thanks
Re: How Can I Attach A Text File To A VB.NET Program by blenyo11(m): 10:32pm On Nov 12, 2012
You will need the ReadAllText method File class from the System.IO namespace.
To have access to the File Class, you need to import the the System.IO namespace
Then you will have to change the name of that variable you name "file" to something
else so as to stop ambiguity of name with the File class that you will be accessing through
the System.IO namespace.

The code below is from the example program I created for you

Imports System.IO
Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "open a file"
OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.Filter = "Text file|*.txt"

OpenFileDialog1.ShowDialog()
Dim fileName As String = OpenFileDialog1.FileName

Dim fileContent As String = File.ReadAllText(fileName)
rtbOutCome.Text = fileContent
End Sub


End Class


I have also attached the sample program in a zip file. It was
created in VS 2010

Re: How Can I Attach A Text File To A VB.NET Program by Lakulos(m): 11:00am On Nov 13, 2012
blenyo11: You will need the ReadAllText method File class from the System.IO namespace.
To have access to the File Class, you need to import the the System.IO namespace
Then you will have to change the name of that variable you name "file" to something
else so as to stop ambiguity of name with the File class that you will be accessing through
the System.IO namespace.

The code below is from the example program I created for you

Imports System.IO
Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "open a file"
OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.Filter = "Text file|*.txt"

OpenFileDialog1.ShowDialog()
Dim fileName As String = OpenFileDialog1.FileName

Dim fileContent As String = File.ReadAllText(fileName)
rtbOutCome.Text = fileContent
End Sub


End Class


I have also attached the sample program in a zip file. It was
created in VS 2010



Its now working,thanks i really appreciate ur concern
Re: How Can I Attach A Text File To A VB.NET Program by blenyo11(m): 12:07am On Nov 14, 2012
Lakulos:



Its now working,thanks i really appreciate ur concern
You are welcome

(1) (Reply)

Seat Booking System PHP / Sneak Peek Of Windows 9 / Help Fix This Android Studio Error Dhtml18 And Otherd

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.