Results 1 to 5 of 5

Thread: [RESOLVED] How to check if a file on a server exists or not

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    Resolved [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

  2. #2
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    351

    Re: How to check if a file on a server exists or not

    Rico

    Using: VB.net & MS SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    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
  •  



Click Here to Expand Forum to Full Width