Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Aperture

macrumors 68000
Original poster
Hey Everyone,

I've been learning how to use the IO.StreamReader command in Visual Basic and I wanted to know if it is possible to use IO.StreamReader to read the contents of a txt file on a web server, as opposed to just a local file. Also, is it possible to have VB write to a txt file on a web server?

The idea behind this is to have an application running on all the client computers and every so often have the application to find a txt file on a webserver and have it display the contents.

Thanks
 
I dug up some of my old .NET code and found a C# class I had used. You need to create a WebRequest object, then use its GetResponse() method to get a WebResponse object, then use the WebResponse method GetResponseStream() to return a Stream. From the Stream object you can build a StreamReader to read the downloaded content.
 
Hey Everyone,

I've been learning how to use the IO.StreamReader command in Visual Basic and I wanted to know if it is possible to use IO.StreamReader to read the contents of a txt file on a web server, as opposed to just a local file. Also, is it possible to have VB write to a txt file on a web server?

The idea behind this is to have an application running on all the client computers and every so often have the application to find a txt file on a webserver and have it display the contents.

Thanks

No you can't read files on a server. You have to use HTTP to get anything from a web server.

But you are in luck because there is a widely used free utility that does what you need "wget" that will pull files from a web server. You don't have to write a program just a short script. Maybe just pipe wget's output to "grep" and look for the string you want.
See more here http://www.gnu.org/software/wget/

Put wget inside a short shell script and have it run periodically from the cron table. (See "man cron".)
 
kainjow, I used your method and I'm still having some trouble. Here is my code so far..

Code:
Imports System
Imports System.IO
Imports System.Net
Imports System.Text

Public Class Form1
    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Dim sURL As String
        sURL = "http://www.URL.com/test.txt"

        Dim wrGETURL As WebRequest
        wrGETURL = WebRequest.Create(sURL)

        Dim objStream As Stream
        objStream = wrGETURL.GetResponse.GetResponseStream()

        Dim sr As IO.StreamReader = IO.File.OpenText([COLOR="Red"][U][B]objStream[/B][/U][/COLOR])[I] (See below)
[/I]
        Dim read As String
        objStream = [COLOR="SeaGreen"][U][B]sr.ReadLine[/B][/U][/COLOR] [I](See below)[/I]

        lstOutput.Items.Add(read)

        objStream.Close()
    End Sub
End Class


"Value of type 'System.IO.String' cannot be converted to 'String'."

"Value of type 'String' cannot be converted to 'System.IO.Stream'."

Any Ideas?

Thanks
 
Reading from .txt file on server.

Idk about writing a file (I would like to know how to do this also..)
But for reading a file, you could do this:

Code:
Dim Web As New WebClient
Dim TXT As String = Web.DownloadString("yourURL.txt")
BoxWithText.Text = (TXT)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.