Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If file exists 2

Status
Not open for further replies.

madanthrax

IS-IT--Management
Sep 15, 2001
123
AT
Hi guys,

I know how to check if a file exists on the webserver an asp page resides on, but does anyone know if you can check an type of path to see if a file exists?

I have an associated site on another server that stores its pdf files (several thousand) using a naming convention and keeps them in one folder. Document versions have an extra f at the end for french, s for spanish etc. A typical english version filename would be DS2402.pdf with DS2402f.pdf for the french translation. I have an SQL view of all the doc numbers and english version filenames in my database with the docs details. (I have access to their tables)

If I can check the other site for french, spanish etc files (up to 7 languages) I can use a simple 'if file ? exists then' in the recordset loop to put the word 'french version' in with a hyperlink to the file if the doc comes in a french version. The associated site finds non english versions for its page links this way, they of course can search their own folders using asp. Why they did not put all the filenames in the DB is a good question, too late now (bad design).

If you have any ideas I thank you.

Ant





"Nothing is impossible until proven otherwise"
 
I'm 99.9% certain that you can't do this with ASP. Happy to be proved wrong though.

Is it really too late to update the database to include all the language variants?

Also - wouldn't it be worth using the ISO country code at the end of the filename rather than just a single letter (eg: fr, es, de, etc...). What happens when you have Spanish and Swedish translations in the future (or Polish and Portuguese)?

Tony

Spirax-Sarco - steam traps control valves heat exchangers
Sun Villa - Luxury Florida accommodation
 
we do a check to see if that URL is valid or not...does that help you?

-DNG
 
If the other site is YOUR site then perhaps you could just add an ASP page over there that checks if the file exists... you pass the url in the querystring and then if it finds the file it outputs a simple one line "web page" with TRUE or FALSE ... no other markup or tags... just TRUE or FALSE.

Then you could use the server-safe version of xmlhttp (MSXML2.ServerXMLHTTP) to call that remote page.

If the other site is not your site then you could still use the xmlhttp but you'd be pulling the entire pdf file just to check if it is there... hope the pdf files are small.

Actually if xmlhttp is capable of sending a "HEAD" HTTP Request instead of a typical "GET" HTTP Request then you can just use the remote web server's "web serverness" to do this for you... it might be worth writing an ActiveX DLL of your own if xmlhttp doesn't do this.
 
Thanks for the responses guys.

Fester & Sheco:
The other website is not mine, its on another physical server. We share the same SQL server though, but getting them to give me permission to access a few of their tables was like I was asking them to run naked down the street. Their DB is setup really crap (not that I'm that wonderful). With many joins I get the info out I need, but there are no records of non english versions.

I like the idea of an asp page on their server, good lateral thinking, but they will never let it happen.

xmlhttp sounds exciting, what is it?

DotNetGnat: How do you do a check to see if a remote file is valid?

Ant


"Nothing is impossible until proven otherwise"
 
here is the sample code:

Code:
<%
'Timeout values in milliseconds
lngResolveTimeout = 500
lngConnectTimeout = 500
lngSendTimeout = 500
lngReceiveTimeout = 500

strTestUrl = "[URL unfurl="true"]http://www.microsoft.com/nonexistingpage.html"[/URL]

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


-DNG
 
Whoa!

Just returned from MSDN after looking at the xmlhttp documentation.... had to take a couple of asprins.

DotNetGnat what can I say, all laid out before me....
Whatever they are paying you its not enough.

I take it by the <% %> that I just slip this in to my asp page wherever I need it?

Ant

&quot;Nothing is impossible until proven otherwise&quot;
 
no problem...glad to be of help...

yes..you can slip it in your asp page without any problem..

-DNG
 
What happens if the remote pdf is a really big file?

500 milliseconds is like half a second so won't it time out if the file is big?

Can you use xmlhttp to do a HEAD instead of a GET ?
 
yes we can do this:
.Open "HEAD", strTestUrl instead of

.Open "GET", strTestUrl


-DNG
 
Code:
With a HEAD request, a server will only return the headers of a resource, rather than the resource itself, this means you can find out the Content-Type or Last-Modified of a document, without downloading it itself.

-DNG
 
DotNetGnat

Just tried the code this am and it works like a charm. The biggest pdf I could find was 4.5mb and it worked instantly. Having seen the recent comment from Sheco, is the code opening the pdf? surely not? its too quick?

There may be bigger pdfs coming so what do you think is best? Open HEAD or stick with your original code?

I know I already said thanks, but this is so kickass good I'll say it again.

Ant.

&quot;Nothing is impossible until proven otherwise&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top