I'm doing an asp.net application but am using vb.net to code the example i'm working on. I'm creating a form that will show historic stock prices I have three description and value pairs:

Company Name stock symbol

Hartford har
Vertigo ver
Dickson dks

I have created three sequential files that have the same name as the symbol with the suffix of .txt. For example har.txt. They have the path c:\turbo.

The symbols are selected using a dropdownlist box.the user then clicks a submit button which makes the selected data apear in the mutiline textbox.

i'm really having a tough time trying to even find a way to start. could use some help.

Recommended Answers

All 5 Replies

So this is a web app then, correct? Then the files should be in a folder accesible to the web app, not the root of your server.

Do you need help using StreamReader, then?

Yes I need help with the streamReader. This is just a practice excercise and will not really be put on the web. The text files are on a shared folder that shouldn't be a problem. I've looked this up in two book I'm just not getting it.

Thanks

Ok, well, then ignoring all the details about web and shared folders, we'll focus just on StreamReader.

1. Import the correct namespace, which in this case would be: System.IO

2. Define the StreamReader. You can define in combination with its constructor. In C#, for example:

StreamReader sr = new StreamReader("TestFile.txt");

3. Read from it, into a string:

string line;

while ((line = sr.ReadLine()) != null) 
{
  //Do Something
}

There are lots of variations. One thing I like to do is first create a FileStream object, and point that to my file. This gives me a lot of control over the access method, whether I want to share the file, and so on.

Then, I use a StreamReader constructor that creates a Streamreader from the FileStream.

Notes: Streamreader is buffered, so it's very fast, but you can often get lost in where you THINK the file is positioned, and where it actually IS positioned.

I'm sure you have more questions, just keep asking within this thread.

I can see I'm going to be asking a lot of questions. Since this is a asp.net I'm not sure how you import a namespace. Would this work:

Dim psrdCurrent as system.IO.Streamreader = New system.IO.StreamReader(path and file name to open)

ASP.NET or Windows Forms, it doesn't matter. Anything in the .NET Framework can be imported. It's a way of aliasing a namespace. You do it at the top of your program:

C#

using System.IO;

VB.NET

Imports System.IO
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.