Results 1 to 8 of 8

Thread: StreamReader

  1. #1

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    StreamReader

    Code:
    StreamReader read;
    read = new StreamReader(File.OpenRead("f:\\test.txt"));
    this.TextBox1.Text = read;
    how do i get this to work? how do i convert it from System.IO.Stream into a string

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    umm I believe you have to call a method or something. I dont do C# so I'm not 100% sure but try this:
    this.TextBox1.Text = read.ReadLine();
    Last edited by MrPolite; Aug 12th, 2002 at 03:58 PM.

  3. #3

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    yer thanks it worked

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

  5. #5

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    Code:
    StreamReader read = new StreamReader(File.OpenRead("F:\\test.txt"));
    while(read.Read())
    {
    this.txtHosts.Text = this.txtHosts.Text + read.ReadLine() + (Char)13;
    }
    i ve try to get it to read all the lines, but its says i cant convert and int to a bool? im not using an int, im using a string? or have i got totaly messed up somewhere?

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    This is probably what you wanted to do..
    Code:
    StreamReader re = File.OpenText(sFile);
    string input = null;
    while ((input = re.ReadLine()) != null)
    {
         this.txtHosts.Text += input;
    }
    re.Close();
    Or, you can do this I think...
    Seems like this would make the most sense from what I see of your code. It reads in the whole file at once instead of looping.
    Code:
    StreamReader sr = new StreamReader(
                (System.IO.Stream)File.OpenRead("C:\\Temp\\Test.txt"),
             System.Text.Encoding.ASCII);
    sr.BaseStream.Seek(0, SeekOrigin.Begin);
    this.txtHosts.Text =sr.ReadToEnd();
    sr.Close();

  7. #7
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by john tindell
    Code:
    StreamReader read = new StreamReader(File.OpenRead("F:\\test.txt"));
    while(read.Read())
    {
    this.txtHosts.Text = this.txtHosts.Text + read.ReadLine() + (Char)13;
    }
    i ve try to get it to read all the lines, but its says i cant convert and int to a bool? im not using an int, im using a string? or have i got totaly messed up somewhere?
    well I actually had to do this in C#, yay! first time I used c#

    Umm change your loop to this

    while(read.Peek() != -1) { .....

  8. #8

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    thanks tonns

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width