Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 24, 2007, 08:57 PM   #1
Aperture
macrumors 68000
 
Aperture's Avatar
 
Join Date: Mar 2006
Location: PA
Send a message via AIM to Aperture
VB - Reading/Writing from txt file on server

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
Aperture is offline   0 Reply With Quote
Old Nov 25, 2007, 01:00 PM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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.
kainjow is offline   0 Reply With Quote
Old Nov 25, 2007, 02:10 PM   #3
ChrisA
macrumors G4
 
Join Date: Jan 2006
Location: Redondo Beach, California
Quote:
Originally Posted by Aperture View Post
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".)
ChrisA is offline   0 Reply With Quote
Old Nov 29, 2007, 09:48 PM   #4
Aperture
Thread Starter
macrumors 68000
 
Aperture's Avatar
 
Join Date: Mar 2006
Location: PA
Send a message via AIM to Aperture
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(objStream) (See below)

        Dim read As String
        objStream = sr.ReadLine (See below)

        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
Aperture is offline   0 Reply With Quote
Old Dec 14, 2011, 01:30 PM   #5
LL2
macrumors newbie
 
Join Date: Dec 2011
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)
LL2 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: OS X Lion installed on partition - how to change read/write permissions JayS90 OS X 2 Oct 4, 2011 11:47 AM
PHD's and Home Sync on Lion Server - iPhoto & PhotoBooth Package files gazcross Mac OS X Server, Xserve, and Networking 4 Sep 26, 2011 07:21 AM
Reading and writing files and storage locations xcode portreathbeach iPhone/iPad Programming 1 Apr 2, 2011 06:22 PM
Ext2 Ext2 Partition - Read/Write acces in Windows and OSX? Mac6272 Windows, Linux & Others on the Mac 0 Oct 27, 2007 02:15 PM


All times are GMT -5. The time now is 06:58 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC