|
-
Feb 8th, 2011, 08:11 AM
#1
Thread Starter
Lively Member
[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
-
Feb 8th, 2011, 10:15 AM
#2
Hyperactive Member
Re: How to check if a file on a server exists or not
Rico
Using: VB.net & MS SQL
-
Feb 8th, 2011, 10:52 AM
#3
Thread Starter
Lively Member
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
-
Feb 8th, 2011, 10:55 AM
#4
Thread Starter
Lively Member
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
-
Feb 8th, 2011, 12:36 PM
#5
Thread Starter
Lively Member
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|