Entwickler-Ecke

IO, XML und Registry - Verzeichnis auf Zugriffsrechte Prüfen


nobelo - Do 22.11.07 00:48
Titel: Verzeichnis auf Zugriffsrechte Prüfen
Hallo Leute,

Ich will eine Methode schreiben, die true zurückgibt wenn das Verzeichnis zugriffbar ist und false wenn nicht. Es handelt sich um ein Verzeichnis im Netzwerk.

folgendes habe ich:



C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
public void isWriteable()
        {
            pathC = ConfigurationManager.AppSettings.Get("PathC");
            DirectoryInfo dInfo = new DirectoryInfo(pathC);

            if (Directory.Exists(pathC))
            {
                try
                {
                    DirectorySecurity dSecurity = dInfo.GetAccessControl();
                    Console.WriteLine("Rechte");
                }
                catch (Exception)
                {
                    //throw new UnauthorizedAccessException("Keine Rechte");
                    Console.WriteLine("Keine Rechte");                    
                }
            }
            else
            {
                throw new Exception("Verzeichnis existiert nicht");
            }
        }



Doch wie bekommen ich aus der GetAccessControl() Methode einen booleschen Wert zurück? Oder hat jemand ne andere Idee?

Gruß

nobelo

Moderiert von user profile iconChristian S.: C#-Tags hinzugefügt
Moderiert von user profile iconChristian S.: Topic aus Sonstiges (C# / .NET) verschoben am Do 22.11.2007 um 00:04


maro158 - Di 27.11.07 15:00

Wirf mal einen Blick auf http://www.codeproject.com/useritems/UserFileAccessRights.asp