Search code examples
visual-studio-2015basic

How to get text data from an url file with visual basic


I'm trying to read and save a text file from an URL (api.ivao.aero/getdata/whazzup/whazzup.txt) with Visual Basic but I couldn't find the syntax to download it. It even will be enough if I can read this text and write it to a TextBox. (Visual Studio 2015)


Solution

  • Yes it can be done.

    Import these :

    Imports System.IO
    Imports System.Text
    Imports System.Net
    

    Then try this:

    Dim address As String = "http://api.ivao.aero/getdata/whazzup/whazzup.txt"
    Dim client As WebClient = New WebClient()
    Dim reader As StreamReader = New StreamReader(client.OpenRead(address))
    Textbox2.Text = reader.ReadToEnd
    

    The text from the url will be displayed/read in textbox2. To have better idea/knowledge about using StreamReader to Read Text from Files, you may read this article. Hope it helps.