Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 974913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:30:16+00:00 2026-05-16T03:30:16+00:00

Working on an application to parse robots.txt. I wrote myself a method that pulled

  • 0

Working on an application to parse robots.txt. I wrote myself a method that pulled the the file from a webserver, and threw the ouput into a textbox. I would like the output to display a single line of text for every line thats in the file, just as it would appear if you were looking at the robots.txt normally, however the ouput in my textbox is all of the lines of text without carriage returns or line breaks. So I thought I’d be crafty, make a string[] for all the lines, make a foreach loop and all would be well. Alas that did not work, so then I thought I would try System.Enviornment.Newline, still not working. Here’s the code as it sounds now….how can I change this so I get all the individual lines of robots.txt as opposed to a bunch of text cobbled together?

public void getRobots()
{
    WebClient wClient = new WebClient();
    string url = String.Format("http://{0}/robots.txt", urlBox.Text);

    try
    {
        Stream data = wClient.OpenRead(url);
        StreamReader read = new StreamReader(data);
        string[] lines = new string[] { read.ReadToEnd() };

        foreach (string line in lines)
        {
            textBox1.AppendText(line + System.Environment.NewLine);
        }
    }
    catch (WebException ex)
    {
        MessageBox.Show(ex.Message, null, MessageBoxButtons.OK);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:30:16+00:00Added an answer on May 16, 2026 at 3:30 am

    You are reading the entire file into the first element of the lines array:

    string[] lines = new string[] {read.ReadToEnd()};
    

    So all your loop is doing is adding the whole contents of the file into the TextBox, followed by a newline character. Replace that line with these:

    string content = read.ReadToEnd();
    string[] lines = content.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
    

    And see if that works.

    Edit: an alternative and perhaps more efficient way, as per Fish’s comment below about reading line by line—replace the code within the try block with this:

    Stream data = wClient.OpenRead(url);
    StreamReader read = new StreamReader(data);
    
    while (read.Peek() >= 0) 
    {
        textBox1.AppendText(read.ReadLine() + System.Environment.NewLine);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone, I'm working on a PHP application that needs to parse a .tpl
I'm working on an Android application. I have an activity that has this method:
We're working on an application that displays information through a Direct3D visualisation. A late
I am working on an application that installs a system wide keyboard hook. I
I am working on an application that is about 250,000 lines of code. I'm
I am working on an application that detects the most prominent rectangle in an
I am working on an application that will allow users to create queries on
I need to parse algebraic expressions for an application I'm working on and am
I am working on an Android application that parses one or more XML feeds
I am working on a .NET 3.5 Windows Forms application that will interact with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.