Finding If Image Exists on Server

statbat
07-22-2002, 04:12 AM
Hi,

I want to put Image in my webpage but if the image does not exist on the server then the asp page should not output <img> tag.

So how in asp can I find that image file example 1200.jpg does exists.

~Statbat();

ChiefRedBull
07-22-2002, 04:38 AM
I think you can use the Dir$() command - it works with VB, so I'd assume it works with VBS... it not, check out the FSO, or the class I just posted in the Code Library (Under the VB File Handling thread).

Rezner
07-22-2002, 08:08 AM
You can't use the Len(Dir(FullFilePath)) method. The FileSystemObject provides a useful function to determine whether or not a file exists, aptly named "FileExists":

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Dim objTextStream

const strFileName = "C:\inetpub\wwwroot\test\wow.txt"
const fsoForReading = 1

If objFSO.FileExists("D:\scott\resume.txt") then
'The file exists, so open it and output its contents
Set objTextStream = objFSO.OpenTextFile(strFileName, fsoForReading)
Response.Write "" & objTextStream.ReadAll & ""
objTextStream.Close
Set objTextStream = Nothing
Else
'The file did not exist
Response.Write strFileName & " was not found."
End If

'Clean up
Set objFSO = Nothing

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum