Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Security / February 2008

Tip: Looking for answers? Try searching our database.

How to find out whether I can enumerate files in a directory?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cody - 22 Feb 2008 22:15 GMT
I tried the following but it tells me for every folder on my pc that I
would not have access to it.
What did I wrong? When it comes to CAS I'am a complete moron..

if (new FileIOPermission(FileIOPermissionAccess.PathDiscovery,path)
    .IsUnrestricted())
            {
                files = Directory.GetFiles(path);

            }
            else
            {
                acessDenied = true;
            }
Henning Krause [MVP - Exchange] - 24 Feb 2008 20:51 GMT
Hello,

you have to deal with several security layers here:

CAS - Your application may run in a zone which prevents you from accessing
files on the computer
NTFS Permissions - The security descriptor on the directory does not permit
access to the user account running under which your program runs.

And the latter is difficult to detect unless you just try it:

try {
        files = Directory.GetFiles(path);
}
catch (UnauthorizedAccessException) {
   accessDenied = true;
}
catch (SecuriyException) {
   accessDenied = true;
}

Kind regards,
Henning Krause

>I tried the following but it tells me for every folder on my pc that I
>would not have access to it.
[quoted text clipped - 10 lines]
>                 acessDenied = true;
>             }
cody - 25 Feb 2008 00:03 GMT
> you have to deal with several security layers here:
>
[quoted text clipped - 14 lines]
>    accessDenied = true;
> }

That's bad, as this is what Iam currently doing. The lot of exceptions
thrown and popping off in Visual Studio annoy me (I know I can turn this
off) and I thought it is not good style.
But it looks like I have to go with it..

Nevertheless, thank you for clearing things up for me!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.