Check if file on intranet exists

G

Guest

I need to check if a file with path "http://pmnet/113-FR-001.xls" exists
without opening it. I've tried using Dir(myPath) but I get an error 52 'Bad
file name or number'. I've also tried using the FileExists method in VB but
I'm not sure how to use it.

Thanks
 
G

Guest

http (hyper-text transfer protocol) is a transfer protocol and cannot be used
to check if a file exists. In some cases you can use File:// when generating
webpages.

the DIR command cannot be used directly to check for a file on internet.
One thing you can do is add a network drive in you window explorer. Go to
explorer and under tools "Map Netwrok drive". Assign a drive letter to
pmnet. Then you can use the drive letter and file name in the DIR command.
 
T

Tim Williams

Use xmlhttp and a "HEAD" request:

'***********************
Function HttpExists(sURL As String) As Boolean
Dim oXHTTP As Object
Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
oXHTTP.Open "HEAD", sURL, False
oXHTTP.send
HttpExists = (oXHTTP.Status = 200)
End Function
'***********************

Tim
 
G

Guest

That's it works perfectly! Thanks a lot.

Tim Williams said:
Use xmlhttp and a "HEAD" request:

'***********************
Function HttpExists(sURL As String) As Boolean
Dim oXHTTP As Object
Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
oXHTTP.Open "HEAD", sURL, False
oXHTTP.send
HttpExists = (oXHTTP.Status = 200)
End Function
'***********************

Tim
 

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

Similar Threads


Top