chris

chris

  • NA
  • 20
  • 0

Download text + Search

Jan 14 2009 8:34 PM
I'm pretty new to c#. Basically there is a database that updates everyday on a webpage and it is a text file. (Example URL "example.com/php.203/list.txt")

As you can see it ends in .txt so I want to basically save that page as a text file within the application. I don't want the user to see any "save dialog" interface. Then I want it to search through the text file for the textBox1.Text and if it is found, label1 is visible if it is not found label1 is visible and text changes. I have some sample code I tried compiling but can't seem to get it working.

NOTE: If it would be easier and more efficient to just go to the webpage instead of download the text file then that would be fine. All I need to do is see if the text is in the text database.

Here's my code:

        private void button1_Click(object sender, EventArgs e)
        {
            {
                string htmlText = string.Empty;
                StreamReader readerText = default(StreamReader);
                Stream WebStream = default(Stream);
                HttpWebResponse WebResponse = default(HttpWebResponse);
                HttpWebRequest request = WebRequest.Create("MY WAB PAGE.TXT");
                string SearchString = textBox1.Text;
                WebResponse = request.GetResponse();
                Webstream = Webresponse.GetResponseStream();
                readerText = new StreamReader(Webstream);
                htmlText = readerText.ReadToEnd();
                if (htmlText.Contains(SearchString))
                {
                    label3.Visible = true;
                }
                else
                {
                    label3.Text = "Not found";
                    label3.Visible = true;
                }
                readerText.Close();
                WebStream.Close();
                WebResponse.Close();
            }

        }

But that code has many errors.

Answers (5)