DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   StreamReaderClass (http://www.daniweb.com/forums/thread24345.html)

augie0216 May 26th, 2005 2:32 am
StreamReaderClass
 
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.

tgreer May 26th, 2005 6:48 pm
Re: StreamReaderClass
 
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?

augie0216 May 27th, 2005 2:18 am
Re: StreamReaderClass
 
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

tgreer May 27th, 2005 10:26 am
Re: StreamReaderClass
 
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.

augie0216 May 28th, 2005 3:23 am
Re: StreamReaderClass
 
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)

tgreer May 28th, 2005 9:34 am
Re: StreamReaderClass
 
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


All times are GMT -4. The time now is 4:08 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC