[RESOLVED] How to check if a file on a server exists or not
Hi,
How can I check if a file exists on a server?
Let's supposed that I want to check if "http://www.mywebsite.com/mytextfile.txt" exists.
How can I do that?
I tried to do this but it does not work:
Code:
Dim fso As New FileObject
If fso.FileExists("http://www.mywebsite.com/mytextfile.txt") Then
MsgBox("exists")
Else
MsgBox("File not found")
End If
Thank you in advance for your help,
Andrea
Re: How to check if a file on a server exists or not
Re: How to check if a file on a server exists or not
Wow That converter almost worked all the way! thank you!
I am not trying to connect via FTP but the code should work anyway!
Here is what I did with what you gave me:
Code:
Dim request = DirectCast(WebRequest.Create _
("http://www.mywebsite.com/mytextfile.txt"), WebRequest)
Try
Dim response As WebResponse = DirectCast(request.GetResponse(), WebResponse)
Catch ex As WebException
Dim response As WebResponse = DirectCast(ex.Response, WebResponse)
MsgBox("no exist")
End Try
If the file does not exists the msgbox come out telling me "no exist" GREAT IT WORKS!
But if the file exists what should i do? How can i implement:
if the file exists msgbox ("yes, the file exists")
Thanks a lot,
Andrea
Re: How to check if a file on a server exists or not
sorry i just figured it out!
Code:
Dim response As WebResponse = DirectCast(request.GetResponse(), WebResponse)
MsgBox("exist")
Catch ex As WebException
Dim response As WebResponse = DirectCast(ex.Response, WebResponse)
MsgBox("no exist")
Now I try to implement more stuff and see if I can get it to work!
I will report back soon.
Thank you,
Andrea
Re: How to check if a file on a server exists or not
Well... what to say...
That converter works quite well!
Amazing!
Thanks a lot Enrico! Awesome!
Regards,
Andrea