Check a file exists on a website
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
![]() |
•
•
Posts: 10
Reputation:
Solved Threads: 0
Currently my users download a database outside my app then from within it they can add the database to their main database. Now I want to have the app download and add the database all at once.
If I change the file extension to .txt the code below downloads the database as a text file but saves it as a mdb.
Dim strURL As String
Dim bData() As Byte ' Data variable
Dim intFile As Integer ' FreeFile variable
strURL = "http://www.asite/update1.txt"
intFile = FreeFile()
bData() = Inet1.OpenURL(strURL, icByteArray)
Open App.Path & "\update1.mdb" For Binary Access Write As #intFile
Put #intFile, , bData()
Close #intFile
But how can I check that the file exists on my site?
If the file doesn't exist, i.e. I haven't added the update to my site yet, the code still creates an update1.mdb that is really a text file that starts:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>The page cannot be found</TITLE>
If I change the file extension to .txt the code below downloads the database as a text file but saves it as a mdb.
Dim strURL As String
Dim bData() As Byte ' Data variable
Dim intFile As Integer ' FreeFile variable
strURL = "http://www.asite/update1.txt"
intFile = FreeFile()
bData() = Inet1.OpenURL(strURL, icByteArray)
Open App.Path & "\update1.mdb" For Binary Access Write As #intFile
Put #intFile, , bData()
Close #intFile
But how can I check that the file exists on my site?
If the file doesn't exist, i.e. I haven't added the update to my site yet, the code still creates an update1.mdb that is really a text file that starts:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>The page cannot be found</TITLE>
•
•
Posts: 10
Reputation:
Solved Threads: 0
Sorry about the code tags.
I've tried the code you attached and edited
Winsock1.RemoteHost = "codefaction.net" to the top level of my site
Send_HTTP_Header Winsock1, "/index.htm" to the path and file name (.txt) of a file I know isn't there
but the app insists the file is "found".
Is this because I am not looking for an HTML file? So when the .txt file is missing it is creates something like when trying to download an .mdb file?
I've tried the code you attached and edited
Winsock1.RemoteHost = "codefaction.net" to the top level of my site
Send_HTTP_Header Winsock1, "/index.htm" to the path and file name (.txt) of a file I know isn't there
but the app insists the file is "found".
Is this because I am not looking for an HTML file? So when the .txt file is missing it is creates something like when trying to download an .mdb file?
What the code does, (at least, what it's supposed to do) is use winsock to connect to the web server. Then it sends an HTTP request header to the server, requesting the page found in path "/index.htm", so if the page was http://www.somesite.com/thisthing/my.txt, then that part would be "/thisthing/my.txt". Then, what the web site does, it check for that file. If the file does not exist, the first line that it responds with, is a 404 (in the response header). So, the code checks for a 404 on the first line returned. What you could consider doing, is doing a msgbox on parts(0) right by the if instr(1, parts(0), "404") line (just above it), and see what it's actual line is.
![]() |
Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- displaying multiple images from DB (MySQL)
- PLS I NEED YOUR HELP! Help on Reading and Editing of already Written CODE on php! (PHP)
- How to create rss.php file (PHP)
- Login through database (ASP)
- Excel integration with the ASP.net over VB (ASP.NET)
- Pls Help Me Out (ASP.NET)
- Pictures appear as red x's (Web Browsers)
- Problems in Dynaform (Form Mail) URGENT HELP (PHP)
- how do I revive our website (IT Professionals' Lounge)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Help! Print the Text in a Textbox and / or Label to Printer
- Next Thread: showing report groupwise in a data report
•
•
•
•
Views: 891 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)






Linear Mode