none
Get file permissions

Answers

  • Hi


    using System.Security.AccessControl;

     

    private void _btnCheck_Permissions_Clicked(object sender, EventArgs e)

    {

      DirectorySecurity ds = new DirectorySecurity(@"D:\Test", AccessControlSections.All);

       try

       {

        Type t = Type.GetType("System.Security.Principal.SecurityIdentifier");

        ir = ds.GetOwner(t);

        Console.WriteLine("Owner: {0}", ir);

     

        arc = ds.GetAccessRules(true, true, t);

        if (arc != null)

         {

          foreach (AuthorizationRule ar in arc)

           {

            AccessRule aru = (AccessRule)ar;

            Console.WriteLine("ID={0}, AccessType={1}", ar.IdentityReference, aru.AccessControlType);

           }

         }

      }

      catch (Exception ex)

       {

         Console.WriteLine(ex.Message);

         Console.WriteLine(ex.StackTrace);

       }

    }


    Hope this helps.

    Tuesday, May 23, 2006 10:39 AM

All replies

  • Hi


    using System.Security.AccessControl;

     

    private void _btnCheck_Permissions_Clicked(object sender, EventArgs e)

    {

      DirectorySecurity ds = new DirectorySecurity(@"D:\Test", AccessControlSections.All);

       try

       {

        Type t = Type.GetType("System.Security.Principal.SecurityIdentifier");

        ir = ds.GetOwner(t);

        Console.WriteLine("Owner: {0}", ir);

     

        arc = ds.GetAccessRules(true, true, t);

        if (arc != null)

         {

          foreach (AuthorizationRule ar in arc)

           {

            AccessRule aru = (AccessRule)ar;

            Console.WriteLine("ID={0}, AccessType={1}", ar.IdentityReference, aru.AccessControlType);

           }

         }

      }

      catch (Exception ex)

       {

         Console.WriteLine(ex.Message);

         Console.WriteLine(ex.StackTrace);

       }

    }


    Hope this helps.

    Tuesday, May 23, 2006 10:39 AM
  • that looks like it Sibusiso, what I want to do is get the file permissions, change the file permissions and then revert back to the original file permissions.
    Thanks.
    Tuesday, May 23, 2006 11:11 AM