Detecting Internet Site

J

J Streger

I am writing code to go out to a sharepoint and grab files from the
sharepoint. I have encountered lots of issues as my workplace doesn't have
that handy .ocx library that has the ability to detect if files exist on the
internet. I cannot install 3rd party applications or use anything that isn't
in the general system ghost.

So I was hoping there would be a Windows API call that could detect if a
file/website exists. Currently I have the following (which I grabbed
partially from another site). It detects if a file exists at a website, but
if the website doesn't exist it just creates the file and returns 1 saying
the file exists:

Public Function InternetFileExists(sPath As String) As Long

Dim HTML As HTMLDocument
Dim tHTML As HTMLDocument
Dim lRet As Long

On Error GoTo CATCHERROR

'Create new HTML Doc
Set tHTML = New HTMLDocument

'Create a document from the URL Path
Set HTML = tHTML.createDocumentFromUrl(sPath, vbNullString)

'wait for the document to load
Do While HTML.readyState <> "complete"
DoEvents
Loop

'Test to see if a 404 or similar error is found
If InStr(1, LCase(HTML.body.innerText), "not found") > 0 Then
lRet = 0
Else
lRet = 1
End If

QUICKEXIT:

InternetFileExists = lRet

'Clear Variables
Set HTML = Nothing
Set tHTML = Nothing

Exit Function

CATCHERROR:

lRet = -1
Resume QUICKEXIT

End Function 'InternetFileExists

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

User of MS Office 2003
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top