944,153 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 2618
  • ASP.NET RSS
May 26th, 2005
0

StreamReaderClass

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Light Poster
augie0216 is offline Offline
30 posts
since Mar 2005
May 26th, 2005
0

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?
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
May 27th, 2005
0

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
Reputation Points: 10
Solved Threads: 0
Light Poster
augie0216 is offline Offline
30 posts
since Mar 2005
May 27th, 2005
0

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:

ASP.NET Syntax (Toggle Plain Text)
  1. StreamReader sr = new StreamReader("TestFile.txt");

3. Read from it, into a string:

ASP.NET Syntax (Toggle Plain Text)
  1. string line;
  2.  
  3. while ((line = sr.ReadLine()) != null)
  4. {
  5. //Do Something
  6. }

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.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
May 28th, 2005
0

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)
Reputation Points: 10
Solved Threads: 0
Light Poster
augie0216 is offline Offline
30 posts
since Mar 2005
May 28th, 2005
0

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#
ASP.NET Syntax (Toggle Plain Text)
  1. using System.IO;

VB.NET
ASP.NET Syntax (Toggle Plain Text)
  1. Imports System.IO
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Get submitted values when navigating back with browser back button
Next Thread in ASP.NET Forum Timeline: Server Error message when opening asp.net applicationm





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC