Dir function doesn't work properly

Theo

Newcomer
Joined
Aug 11, 2006
Messages
14
Location
Netherlands
Hi all,

Im trying to use the Dir function to determine wether a certain image excists or not. But the variable strDir is always empty, even when an image does excist. (see code below).

Code:
    Public Function getIMG(ByVal pItem As String) As String
        Dim strDir As String

        strDir = Dir("Z:\images\" & pItem & ".jpg")

        Return strDir
    End Function

- The parameter pItem is the name of the image without the extension.
- All the images have NO attributes
 
Last edited:
The Dir function is really a legacy VB function (and it wasn't that good then) - Try using the classes under System.IO.

e.g.
Visual Basic:
If System.IO.File.Exists("z:\images\" & pItem & ".jpg")
 
PlausiblyDamp said:
The Dir function is really a legacy VB function (and it wasn't that good then) - Try using the classes under System.IO.

e.g.
Visual Basic:
If System.IO.File.Exists("z:\images\" & pItem & ".jpg")


I've adapted my function like you can see below, but without any result. It seems like ASP.NET isn't able to see the existing images.

Code:
    Public Function getIMG(ByVal pItem As String) As String
        Dim strDir As String

        If System.IO.File.Exists("Z:\afbeeldingen\" & pItem & ".jpg") = True Then
            strDir = "Z:\afbeeldingen\" & pItem & ".jpg"
        Else
            strDir = "blank"
        End If

        Return strDir
    End Function
 
PlausiblyDamp said:
Does the ASPNET account have permissions to the Z:\afbeeldingen folder?

That seemed to be the problem. I copied the images to the local drive and now it works fine. So it must be the permissions indeed.

Thanks!
 
Back
Top