473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Open Text File

Thank you in advance for any and all assistance. Is there a way to open a
specific text file in Visual Basic.NET? If so, what is the code?

Michael
Nov 21 '05 #1
7 7805
"Lumpierbritches" <lu*************@aol.com> schrieb:
Thank you in advance for any and all assistance. Is there a way to open a
specific text file in Visual Basic.NET? If so, what is the code?


Reading a text file line-by-line or blockwise with a progress indicator
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2
If I correctly understood your question, this piece of code will read line
by line from a text file and store into a string variable. You can then do
what ever you want with the returns.

Imports System.IO

Private Sub ReadRecord()
Dim filetoread As String

filetoread = "c:\MytextFile.txt"

Dim filestream As StreamReader

filestream = File.OpenText(filetoread)

Dim readcontents As String

Do Until filestream.Peek = -1

readcontents = filestream.ReadLine()

Loop
filestream.Close()
End Sub

"Lumpierbritches" <lu*************@aol.com> wrote in message
news:20***************************@mb-m10.aol.com...
Thank you in advance for any and all assistance. Is there a way to open a
specific text file in Visual Basic.NET? If so, what is the code?

Michael

Nov 21 '05 #3
If I correctly understood your question, this piece of code will read line
by line from a text file and store into a string variable. You can then do
what ever you want with the returns.

Imports System.IO

Private Sub ReadRecord()
Dim filetoread As String

filetoread = "c:\MytextFile.txt"

Dim filestream As StreamReader

filestream = File.OpenText(filetoread)

Dim readcontents As String

Do Until filestream.Peek = -1

readcontents = filestream.ReadLine()

Loop
filestream.Close()
End Sub

"Lumpierbritches" <lu*************@aol.com> wrote in message
news:20***************************@mb-m10.aol.com...
Thank you in advance for any and all assistance. Is there a way to open a
specific text file in Visual Basic.NET? If so, what is the code?

Michael

Nov 21 '05 #4
Dim sr as StreamReader = New StreamReader("Filename.txt")

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5
Dim sr as StreamReader = New StreamReader("Filename.txt")

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #6
Michael,

Just a search for streamreader on MSDN gives you a bunch of information.

This is the first found

http://msdn.microsoft.com/library/de...ClassTopic.asp

I hope this helps?

Cor

"Lumpierbritches"
Thank you in advance for any and all assistance. Is there a way to open a
specific text file in Visual Basic.NET? If so, what is the code?

Michael

Nov 21 '05 #7
Michael,

Just a search for streamreader on MSDN gives you a bunch of information.

This is the first found

http://msdn.microsoft.com/library/de...ClassTopic.asp

I hope this helps?

Cor

"Lumpierbritches"
Thank you in advance for any and all assistance. Is there a way to open a
specific text file in Visual Basic.NET? If so, what is the code?

Michael

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: BadOmen | last post by:
I have a text file that I want to save from my program. But I don't want to save the empty lines. I want to delete everything after the last character, Is that possible? Then when I read the...
3
by: Newbie | last post by:
I am trying to get the save/open dialog figured out. I am able open the save dialog but when I put in a file name (whatever.txt) and save the file does save with the name but it is blank. Below...
3
by: RN Das | last post by:
Hi expert, I have a small web application in C# and ASP.Net and I want to open a file in notepad when clicked on a linked button. Here is hander code when clicked on the link button. It can open...
2
by: Seok Bee | last post by:
Dear Experts, In my web application, I am having a button to open a file located in the server. When I click on the button to view the file, I received the following error message:...
3
by: sohan | last post by:
hi I have hyperlink column in a datagrid. The column contains the name of a text file. I am able to appendthe full path of the file. The file is on D drive on the server. But on clicking on...
2
by: OutdoorGuy | last post by:
Greetings, I have a "newbie" question in relation to opening files from C#. I have a Windows form where I allow the user to type in a file extension in a text box (e.g., "xls"). I then take...
6
by: Moumen VB.NET 2003/2005 Developer | last post by:
How can I detect if a file sitting on a network drive is still open by another application? This application resides on another machine on the network? I am using VB.NET 2003 Your help is...
8
by: someone | last post by:
I'm making an program that encodes text, and then writes it into another text file. The problem is that I can't seem to get the "file exists" checking right. If I use the command (coder is the...
13
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains...
1
by: sunnyluthra1 | last post by:
Hi Everyone, I am working on a piece of code, that displays the properties(Name, Datatype, size & Description) of the table in the database. Now I want to further Enhance the code. I Have created...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.