How to Get Text from Online File .text

Ahmed Ibrahim

I'm creating an application with C# that should should download data as text from a file (found online) at this location: http://asap.eb2a.com/a.text.

I need to get the text data only. My code so far:

//  this.Hide();
//  notifyIcon1.Visible = true;
WebClient Get= new WebClient();
Uri Line = new Uri("http://asap.eb2a.com/a.text");
AAA:
var text = Get.DownloadData(Line);
// var text = System.IO.File.ReadAllText(@"D:\b.txt");
//System.IO.File.Delete(@"D:\Not.text");
label1.Text = text.ToString();
while (text.ToString() == text.ToString())
try
{
    notifyIcon1.Visible = true;
    notifyIcon1.BalloonTipText = (Convert.ToString(text));
    notifyIcon1.BalloonTipTitle = "We Notify You";
    notifyIcon1.ShowBalloonTip(150);
    BBB:   var text1  = Get.DownloadData(Line);
    //System.IO.File.ReadAllText(@"D:\b.txt");
    while(text.ToString()==text1.ToString())
    {
        await Task.Delay(50);
        goto BBB;
    }
    await Task.Delay(50);
    goto AAA; 
}
catch
{
    MessageBox.Show("Error");
}

In order to make sure that the data is not the same I do some loops and I get this in Notify Error With Notification

keenthinker

I assume that your problem is the HTML text showed in the notify icon text. Probably the web site (asap.eb2a.com...) does not allow unknown agents, so it returns some message to inform you or the a.text file contains HTML and JavaScript code. The first problem can be bypassed by adding a header to the WebClient object to mask your call as if it is coming from a web browser:

Get.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

The loops created using the goto/label construct can be replaced by a System.Timers.Timer class. This will also simplify your code:

  • create the WebClient object to call the uri
  • create a variable to preserve the downloaded text
  • create a timer object and bind the Elapsed event, that is called every 100 milliseconds
  • in the timer Elapsed event download the data from the site using the WebClient.DownloadString method
  • compare the already saved text with the newly downloaded string: if their are different, then show the notify icon

The implementation looks like this:

WebClient Get = new WebClient();
// identify your self as a web browser
Get.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Uri uri = Uri("http://asap.eb2a.com/a.text");
string contentToShow = String.Empty;
// timer for the repetitive task called every nnn milliseconds
const long refreshIntervalInMilliseconds = 100;
System.Timers.Timer timer = new System.Timers.Timer(refreshIntervalInMilliseconds);
timer.Elapsed += (s, e) =>
{
    Console.WriteLine(String.Format("{0} Fetching data from: {1}", DateTime.Now, uri));
    try
    {           
        var result = Get.DownloadString(uri);
        if (result != contentToShow)
        {
            contentToShow = result;
            notifyIcon1.Visible = true;
            notifyIcon1.BalloonTipText = contentToShow;
            notifyIcon1.BalloonTipTitle = "We Notify You";
            notifyIcon1.ShowBalloonTip(150);
        }
    }
    catch (Exception exception)
    {
        MessageBox.Show(string.Format("Error: {0}", exception.Message));
    }
};
// start the timer
timer.Start();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How get value from text file in linux

From Dev

How to get VBS to read from text file?

From Dev

How to Get a value from a text file

From Dev

How to get word from text file BASH

From Dev

how to get dictionary elements from text file

From Dev

How to get var value from a text file?

From Dev

Get android:text from online strings

From Dev

Get android:text from online strings

From Dev

How to get output of particular text from text file using batch?

From Dev

How to fetch n text files from online and save it to a single text file

From Dev

How to get the value from rows and columns from text file in bash?

From Dev

How to store text from JOptionPane into text file

From Dev

How to get a particular text from the text box

From Dev

How to get the first line of an input text file, while deleting that line from the text file

From Dev

How to store input data using php into text file and get data from text file?

From Dev

How can I get a specific line from a text file?

From Dev

How can I get a connection string from a text file?

From Dev

How to get text at runtime from XAML file included in project?

From Dev

how to get proxy ip and port from text file

From Dev

How to get 2 separate number averages from a text file?

From Dev

How to get the count of a string from a text file . The output is wrong

From Dev

How to get the window title text from batch file

From Dev

how to get content within a specific text from a file

From Dev

How to get data's from text file in c#

From Dev

How to get only a Particular field from an object array in a text file

From Dev

Text processing - How to get multiple patterns in order from a file

From Dev

How to get only the numbers(without whitespaces) from a text file in python

From Dev

How to get line number from a text file in vb.net

From Dev

How to get the number of lines from a text file in java?

Related Related

  1. 1

    How get value from text file in linux

  2. 2

    How to get VBS to read from text file?

  3. 3

    How to Get a value from a text file

  4. 4

    How to get word from text file BASH

  5. 5

    how to get dictionary elements from text file

  6. 6

    How to get var value from a text file?

  7. 7

    Get android:text from online strings

  8. 8

    Get android:text from online strings

  9. 9

    How to get output of particular text from text file using batch?

  10. 10

    How to fetch n text files from online and save it to a single text file

  11. 11

    How to get the value from rows and columns from text file in bash?

  12. 12

    How to store text from JOptionPane into text file

  13. 13

    How to get a particular text from the text box

  14. 14

    How to get the first line of an input text file, while deleting that line from the text file

  15. 15

    How to store input data using php into text file and get data from text file?

  16. 16

    How can I get a specific line from a text file?

  17. 17

    How can I get a connection string from a text file?

  18. 18

    How to get text at runtime from XAML file included in project?

  19. 19

    how to get proxy ip and port from text file

  20. 20

    How to get 2 separate number averages from a text file?

  21. 21

    How to get the count of a string from a text file . The output is wrong

  22. 22

    How to get the window title text from batch file

  23. 23

    how to get content within a specific text from a file

  24. 24

    How to get data's from text file in c#

  25. 25

    How to get only a Particular field from an object array in a text file

  26. 26

    Text processing - How to get multiple patterns in order from a file

  27. 27

    How to get only the numbers(without whitespaces) from a text file in python

  28. 28

    How to get line number from a text file in vb.net

  29. 29

    How to get the number of lines from a text file in java?

HotTag

Archive