views:

2016

answers:

3

I have a simple file selector on my web application which uses Directory.GetFiles and Directory.GetDirectories to produce the UI. This works perfectly on my localhost, but when I upload it to my Windows Server 2003 hosting I can only see files - on the same directory, GetFiles works but GetDirectories doesn't.

The code is incredibly simple - the string dir is created by a Server.MapPath call, and then:

List<string> dirs = Directory.GetDirectories(dir).ToList();
List<string> files = Directory.GetFiles(dir).ToList();

I have tried everything I can think of security-wise; even to the point of giving "Everyone" full access to all directories in the web root, and even this makes no difference.

So if the issue is not with security, I would be very grateful of some suggestions for more things to try!

Update: I'm pretty dumb - the code that spat out the HTML contained some very old testing code that hadn't made any difference on local so hadn't been noticed and removed, but that caused every directory on the server to be ignored! What was it?

if (!subDir.Contains(".")) { ...

On the server, all sites are in folders named by their domain - on local, they aren't. Me == stupid. Sorry everyone!

A: 

Are the directories hidden?

Are they actual directories, or (since this is a web-server) virtual folders?

Btw - unless you specifically want some of the List<T> features, you might as well leave them in the original string[] arrays... indeed, with 3.5, LINQ blurs the advantages of List<T>, since Where(...), First(...) etc apply to arrays.

Marc Gravell
A: 

Have you checked that the directory is where you think it is? IIS can often put you in a temporary directory, so it may have copied all your files over to this temp folder, but none of the subdirs, so there simply are none.

Orion Edwards
A: 

You can force an exception to be thrown if you do not have permission:

new FileIOPermission(FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read,dir).Demand();
Chad Grant