473,413 Members | 2,066 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,413 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 7806
"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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.