|
 |
asp_databases thread: Test if File Exists
Message #1 by "Rebecca Emerson" <emerson@u...> on Tue, 23 Jan 2001 11:00:22 -0500
|
|
Help!
I am a newbie to ASP. I have a form that has a drop-down combo box where
the user will select an Organization code. Based on the selection, I
concatenate the Organization code to construct the JPG filename. The codes
below works. If the JPG file exists, the LAN/WAN Chart will be displayed,
if not a box with no image is displayed.
<%
Dim imageFile
imageFile = "images/" & session("organization") & "LAN.jpg"
' response.write "imagefile=/" & imagefile & "/"
response.write "<font size='+2'><center><b>" & session("organization")
& " LAN/WAN Chart" & "</b></center></font><p>"
%>
<FORM METHOD = "POST" ACTION = "ViewLANSrch.asp">
<center><font color="blue"><input type="submit" value="Back to LAN/WAN
Organization Search"></font></center>
<table>
<tr>
<td><img src="<%= imagefile %>"></td>
</tr>
</table>
The codes above works, however, I want to make it user-friendly that if it
doesn't find the image file, it will display a message that says there is
no LAN/WAN Chart for that Organization. I had read Ken's reply to Daniel
who also had a similar problem. However, I could not make the codes below
work. Both of my "fileExists" tests came out false. Can someone tell me
what I am doing wrong? Thanks.
Becky
<%
Dim strLANFileName
Dim objLANFile
Dim sQuote
sQuote = chr(34)
strLANFileName = imagefile
Set objLANFile = CreateObject("Scripting.FileSystemObject")
response.write "T/F=" & objLANFile.fileExists(strLANFileName)
response.write "<br>"
response.write "sQuote=/" & sQuote & "/"
strLANFileName = sQuote & imagefile & squote
response.write "<br>"
response.write "strLANFileName=/" & strLANFileName & "/"
response.write "<br>"
response.write "T/F2=" & objLANFile.fileExists(strLANFileName)
response.write "<br>"
If (objLANFile.fileExists(strLANFileName)) = TRUE then
response.write "file exists.."
%>
<td><img src="<%= strLANFileName %>"></td>
<%
else
response.write "file does not exists..."
response.write "<td>"
response.write session("Organization") & "did not submit a "
response.write "LAN/WAN chart. Please click the button '"
response.write "Back to LAN/WAN Organization Search' to select "
response.write "another organization."
response.write "</td>"
end if
%>
<td>   </td>
</tr>
</table>
Message #2 by Imar Spaanjaars <Imar@S...> on Tue, 23 Jan 2001 19:26:18 +0100
|
|
Just a wild guess, but what is the value of strLANFileName?? Is it a
virtual location, like "/images/myImage.jpg" ??
If so, use Server.MapPath(strLANFileName) to "translate" the virtual path
to the actual location on disk.
<CODE>
strLANFileName = "/images/myImage.jpg"
strLANFileName = Server.MapPath(strLANFileName)
</code>
Now strLANFileName contains the real path, for example:
"C:\inetpub\myWebApp\images\myImage.jpg"
Since the FileExists method expects a full path, this should do the trick
HtH
Imar
Message #3 by "Rebecca Emerson" <emerson@u...> on Thu, 25 Jan 2001 14:32:44 -0500
|
|
Imar,
I am sorry that I didn't get back sooner. I just managed to test your
suggestion last night and it WORKS! Thank you for your help and immediate
response.
Becky
|
|
 |