Could anybody help with code? I am trying to read a simple text file from my website that shows whether I have updates turned on or off. I tried the code below and I am getting a nil object exception when trying to set the text file to the folder online. I am trying to avoid downloading the file. Would like to just open and read it from where it is on the website. Thanks for any help you can offer. Here’s the code.
[code]Dim TextFile As FolderItem
Dim TextInput As TextInputStream
Dim s As String
Dim sError As String = “”
'--------------------------------------------------------------
'check for the file and read the first line to see if online.
'Set the boolean to true if online or false if not and get the
'server status message.
TextFile = GetFolderItem(App.WebsiteUpdatePath).Child(“ServerStatus.txt”)
If TextFile <> Nil Then
If TextFile.exists Then
TextInput = TextInputStream.Open(TextFile)
sgServerStatusMessage = TextInput.ReadLine
If InStr(sgServerStatusMessage, "ONLINE") > 0 Then
bgServerOnline = True
Else
bgServerOnline = False
End If
TextInput.Close
End If
Else
sError = “ServerStatus.Text = Nil”
End If
If sError <> “” Then
Return False
Else
Return True
End If [/code]
You’re going to want to look at an HTTPSocket then.
I fully recommend you use the namespaced framework for that since the old framework socket isn’t as helpful.
http://developer.xojo.com/xojo-net-httpsocket
The distinction between “view” and “download” only exists when using a web browser, and it refers to what the browser does after receiving (i.e. downloading) the data.
Use the HTTPSocket like Tim suggests.
[quote=390931:@Andrew Lambert]The distinction between “view” and “download” only exists when using a web browser, and it refers to what the browser does after receiving (i.e. downloading) the data.
Use the HTTPSocket like Tim suggests.[/quote]
I have other code that uses the http socket to download the file. Does this mean that the file cannot be just opened from where it sits on the web server? I have to download it? How else could I do this. Just want to be able to say yes or no to whether my update app is allowed to get the update files or not.
Unless your web server is serving files from a drive that your app can access directly, you have to use HTTPSocket to get the contents of that file.
Correct. You can’t directly access the file on the server like you would with a local file, you can only ask the server to send its contents.