[VB] Checken of een remote file bestaat of niet

Pagina: 1
Acties:

  • Toink
  • Registratie: Januari 2000
  • Niet online
Hoi,

Ik heb een applicatie in elkaar gedraaid die bestanden kan downloaden op een simpele manier via een inet-control. Het probleem is echter dat wanneer een bestand niet bestaat, dan downloadt ie de foutmelding en dat is niet de bedoeling. Ik wil graag ervoor een check plaats laten vinden of een bepaald bestand wel bestaat. Het is trouwens geen interactief programma. Van tevoren staat al vast dat ik een bepaald bestand moet binnenhalen dus het is niet via een browser ofzo.

maw: http://www.google.nl/images/hp0.gif

Dit is een plaatje van de website van google (JOH! :)). Hoe kan ik controleren of dit bestand bestaat? Heb al van alles rondgezocht op internet maar de keywords zijn een beetje lastig. Hopelijk kan hier iemand me verder helpen.

Verwijderd

/me lol
Ik denk dat je wat moet gaan lezen over error handling en HTTP status meldingen. Als je namelijk een HTTP 404 melding krijgt, bestaat het plaatje niet, en moet je dat aan de gebruiker melden.

Enjoy :)

  • LordLarry
  • Registratie: Juli 2001
  • Niet online

LordLarry

Aut disce aut discede

Inderdaad, MrX heeft gelijk. Het HTTP protocol, wat je hier gebruikt, heeft die mogelijkheid gewoon niet. Gewoon behoorlijke foutcontrole in je programma maken.

We adore chaos because we like to restore order - M.C. Escher


Verwijderd

LordLarry schreef op 16 oktober 2002 @ 09:42:
Inderdaad, MrX heeft gelijk. Het HTTP protocol, wat je hier gebruikt, heeft die mogelijkheid gewoon niet. Gewoon behoorlijke foutcontrole in je programma maken.
Uhm ... HTTP heeft dat dus wel, en dat zijn de status codes. Zie http://www.ietf.org/rfc/rfc2068.txt?number=2068.
6.1.1 Status Code and Reason Phrase

The Status-Code element is a 3-digit integer result code of the
attempt to understand and satisfy the request. These codes are fully
defined in section 10. The Reason-Phrase is intended to give a short
textual description of the Status-Code. The Status-Code is intended
for use by automata and the Reason-Phrase is intended for the human
user. The client is not required to examine or display the Reason-
Phrase.

The first digit of the Status-Code defines the class of response. The
last two digits do not have any categorization role. There are 5
values for the first digit:

o 1xx: Informational - Request received, continuing process

o 2xx: Success - The action was successfully received, understood,
and accepted

o 3xx: Redirection - Further action must be taken in order to
complete the request

o 4xx: Client Error - The request contains bad syntax or cannot be
fulfilled

o 5xx: Server Error - The server failed to fulfill an apparently
valid request

  • Toink
  • Registratie: Januari 2000
  • Niet online
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'Timeout values in milliseconds
lngResolveTimeout = 500
lngConnectTimeout = 500
lngSendTimeout = 500
lngReceiveTimeout = 500

strTestUrl = "http://www.microsoft.com/nonexistingpage.html"

Set objHttpRequest = CreateObject("MSXML2.ServerXMLHTTP")
With objHttpRequest
   .SetTimeouts lngResolveTimeout, lngConnectTimeout, lngSendTimeout, 
lngReceiveTimeout
   .Open "GET", strTestUrl
   .Send
   Select Case .Status
      Case 200 'No problem!
         msgbox strTestUrl & " is a valid, available URL"
      Case 404 'Not found
         msgbox strTestUrl & " could not be found (404 Error)"
      Case Else 'Some other problem
         msgbox "An unexpected HTTP Status value was returned: " & 
.Status
   End Select
End With
Set objHttpRequest = Nothing


Deze doet 't inderdaad! bedankt