PDA

View Full Version : file exists - error


Spudhead
08-12-2003, 12:44 PM
Hey,

OK, this question has 2 parts. 5 points for each successful answer ;)

I've got a quick function that uses FileSystemObject to make sure an image (filename pulled from SQL Server) exists. Roughly:

If (objFSO.FileExists(Server.MapPath(FileName))) = True Then
IsFileExists = True
Else
IsFileExists = False
End If

Pretty basic :) This is falling over on ONE image - the FileName variable passed to the function is "images/Gen_Bali_View_2.jpg", and the error is "An invalid character was specified in the Path parameter for the MapPath method." For the other 9000 images, it works fine....

So - question 1 is: what invalid char would be causing such an error?


The second question centers around my as-yet-unsuccessful attempt at an another approach: the XMLHTTP object. I'm trying to use the following:


Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "GET", strPicPath, False
objXMLHTTP.Send
intHTTPStatus = objXMLHTTP.status
Set objXMLHTTP = Nothing

If intHTTPStatus = 200 Then
IsFileExists = True
Else
IsFileExists = False
End If


Which is falling over on "objXMLHTTP.Send" with a "cannot find remote server" error.

The "strPicPath" variable that's passed to it is the full url of the image (which isn't on a remote server, it's actually in the directory below the file containing the above code snippet). The URL is valid when pasted into a browser.

So - question 2 is: am I using XMLHTTP in a completely misguided way, or do I simply have a bit of a typo?

Thanks :)

raf
08-12-2003, 01:14 PM
Anout XMLHTTP :

This is normally only used to acces remote (XML)-files, so i'm not sure you can use it to get an image from the same machine. It looks to me you don't need XMLHTTP so why bother ?

About the filename:

How about renaming the file? character by character and see what happens ?

Spudhead
08-12-2003, 01:27 PM
I can't rename the file - it's all generated from a remote CMS unfortunately :( Renaming would involve about 4 people from several departments, a week of waiting, and me filling in forms in triplicate :rolleyes:

I assumed that, seeing as the XMLHTTP is passed a full domain url, then it wouldn't mind/notice that the domain it's given is the same as the one that the script is on - but apparently it does :(

I know XMLHTTP is a bit of overkill but I'm not sure what else to try; the FileSystemObject method works for all 9000 other files, the path seems ok, the image is there and doesn't seem to be corrupted or non-standard in any way.

Hmmm.

raf
08-12-2003, 01:58 PM
Hmm. Well, your quick fix could be to first check for the filename, and if it is "images/Gen_Bali_View_2.jpg", then skip the fileexist and set IsFileExists = True

At least your script will keep running and the worst that could happen is that the image could be deleted (which would solve the problem altogether if the db is updated automatically) and you get an "image can not be displayed or whatever"

All the other images also have "image/" and underscores and/or numbers in there adresses? Is this adress longer then any other ?


I wouldn't go the XMLHTTP way as a way to work around this problem.

Spudhead
08-12-2003, 03:58 PM
Yeah, much as I dislike a hardcoded kludge, I can't figure out why on earth this particular file / name is causing problems - it's completely normal looking, and it follows the same naming fomat as the rest of them.

I've filled in a "Content [Non-text] Amendment Request" :rolleyes: :cool: