Directory.Exists - UNC path with access denied c #

I am writing code to access directories and index found files. A user can enter a UNC path and impersonate another user to access this directory. I am using Directory.Exists to check if the path they entered is valid before trying to access it.

This works great for local paths, but when I try to access a UNC path that I know I don't have, Directory.Exists returns true.

My understanding is that Directory.Exists does not check if a particular path can only "access" that it exists or not.

What else can I use to check if a directory exists and I have access to it?

I don't know any of the filenames inside the directory at the moment.

Thank!

+2


source to share


3 answers


Why not just try to index by listing the files and handle the exception thrown when it can't access? There is always the possibility that a subfolder or an individual file may not be accessible anyway, even if you access the specified specific directory.



+2


source


Interesting. I thought \ directory \. will not resolve, although the \ should be ok, but \ directory \. also good, which I think is a mistake, because I think "." the file is under the directory.



0


source


0


source







All Articles