Link to home
Start Free TrialLog in
Avatar of RySk8er30
RySk8er30

asked on

Listing files on network drive

Hi,

How can I list files on a network drive?  I tried this...

        Dim Location As String = "G:\SHARE\ALL\Document Control\" & Request.QueryString("type")

        If Directory.Exists(Location) Then

            Dim files As Object = Directory.GetFiles(Location)
            Dim file As String

            For Each file In files
                lblError.Text += file & ","
            Next

        End If

but it doesn't work.  I can see local files fine, but when I try to see a networked drive it has problems.

Ryan
Avatar of bramsquad
bramsquad
Flag of United States of America image

try using the file objects

        Dim file As FileInfo
        Dim dir As DirectoryInfo = New DirectoryInfo("G:/")

        For Each file In dir.GetFiles

        Next

~b
Avatar of RySk8er30
RySk8er30

ASKER

Hi,

I still get an error:

Could not find a part of the path "G:\".

Any ideas?

Ryan
its becuase its not finding what path you gave it

you want to change my code to work with yours



if you have this line...

If Directory.Exists(Location) Then

then this line

Dim dir As DirectoryInfo = New DirectoryInfo(Location)

should work

~~im assuming that you just have to change "G:/" to your variable Location
Both the Directory.Exist() method and the Directory.Files() method expect a fully-formed path... no wildcards or anything else tacked on to the end.

I presume that you have verified that you have mapped the network drive correctly, and can see files in that path?  (Open a command prompt and do a "dir " and paste the path string onto the line, then hit enter)
Hi,

Even if I do look at the root of G:\ I get nothing.  I have verified that the path exists.

Ryan
       Dim Location As String = "G:\" 'SHARE\ALL\Document Control\" & Request.QueryString("type")

        Dim file As FileInfo
        Dim dir As DirectoryInfo = New DirectoryInfo(Location)

        For Each file In dir.GetFiles()

            lblError.Text += Convert.ToString(file) & ", "

        Next
ASKER CERTIFIED SOLUTION
Avatar of bramsquad
bramsquad
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well this is a drive mapped to a Novell server.  The user who is logged into the web server is the administrator so he has access to all the Novell directories...