当前位置: 首页>>代码示例>>C#>>正文


C# FileSystemRights类代码示例

本文整理汇总了C#中FileSystemRights的典型用法代码示例。如果您正苦于以下问题:C# FileSystemRights类的具体用法?C# FileSystemRights怎么用?C# FileSystemRights使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileSystemRights类属于命名空间,在下文中一共展示了FileSystemRights类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Add

 public static void Add(string Path, string UserName, FileSystemRights Role)
 {
     DirectoryInfo dirinfo = new DirectoryInfo(Path);
     DirectorySecurity sec = dirinfo.GetAccessControl();
     sec.AddAccessRule(new FileSystemAccessRule(UserName, Role, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
     dirinfo.SetAccessControl(sec);
 }
开发者ID:henrydem,项目名称:yongfa365doc,代码行数:7,代码来源:NTFS.cs

示例2: FileHasPermission

        /// <summary>
        /// Test a file for create file access permissions
        /// </summary>
        /// 
        /// <param name="FilePath">Full path to file</param>
        /// <param name="AccessRight">File System right tested</param>
        /// 
        /// <returns>State</returns>
        public static bool FileHasPermission(string FilePath, FileSystemRights AccessRight)
        {
            if (string.IsNullOrEmpty(FilePath)) return false;

            try
            {
                AuthorizationRuleCollection rules = File.GetAccessControl(FilePath).GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier));
                WindowsIdentity identity = WindowsIdentity.GetCurrent();

                foreach (FileSystemAccessRule rule in rules)
                {
                    if (identity.Groups.Contains(rule.IdentityReference))
                    {
                        if ((AccessRight & rule.FileSystemRights) == AccessRight)
                        {
                            if (rule.AccessControlType == AccessControlType.Allow)
                                return true;
                        }
                    }
                }
                return false;
            }
            catch
            {
                throw;
            }
        }
开发者ID:DeadlyEmbrace,项目名称:NTRU-NET,代码行数:35,代码来源:FileUtils.cs

示例3: SetAcl

        private static void SetAcl(string path, SearchResult user, FileSystemRights right)
        {
            var userId = user.Properties["userPrincipalName"][0].ToString();
            var fullUserName = user.Properties["name"][0].ToString();
            var fullPath = path + fullUserName;
            var dir = new DirectoryInfo(fullPath);
            var ds = new DirectorySecurity();
            ds.SetAccessRuleProtection(true, false);

            var uacl = new FileSystemAccessRule(userId,
                right,
                InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                PropagationFlags.None,
                AccessControlType.Allow);
            ds.AddAccessRule(uacl);

            var domainAdmins = new SecurityIdentifier(WellKnownSidType.AccountDomainAdminsSid, AppSettings.GeneralSettings.DomainSid);
            var pacl = new FileSystemAccessRule(domainAdmins,
                FileSystemRights.FullControl,
                InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                PropagationFlags.None,
                AccessControlType.Allow);
            ds.AddAccessRule(pacl);

            var system = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null);
            var sacl = new FileSystemAccessRule(system,
                FileSystemRights.FullControl,
                InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                PropagationFlags.None,
                AccessControlType.Allow);
            ds.AddAccessRule(sacl);

            dir.SetAccessControl(ds);
        }
开发者ID:Kusado,项目名称:WindowsProjects,代码行数:34,代码来源:Program.cs

示例4: AddAclRuleOnDirectory

 private static void AddAclRuleOnDirectory(string directory, IdentityReference identity, FileSystemRights rights, AccessControlType type)
 {
     var acl = Directory.GetAccessControl(directory);
     acl.PurgeAccessRules(identity);
     acl.AddAccessRule(new FileSystemAccessRule(identity, rights, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, type));
     Directory.SetAccessControl(directory, acl);
 }
开发者ID:vviskari,项目名称:MPExtended,代码行数:7,代码来源:EnvironmentChecks.cs

示例5: AddAclRuleOnFile

 private static void AddAclRuleOnFile(string file, IdentityReference identity, FileSystemRights rights, AccessControlType type)
 {
     var acl = File.GetAccessControl(file);
     acl.PurgeAccessRules(identity);
     acl.AddAccessRule(new FileSystemAccessRule(identity, rights, type));
     File.SetAccessControl(file, acl);
 }
开发者ID:vviskari,项目名称:MPExtended,代码行数:7,代码来源:EnvironmentChecks.cs

示例6: HasAccess

        public bool HasAccess(FileSystemRights rights)
        {
            WindowsIdentity user = (WindowsIdentity)principal.Identity;
              // Get the collection of authorization rules that apply to the specified directory
              AuthorizationRuleCollection acl = directory.GetAccessControl().GetAccessRules(true, true, typeof(SecurityIdentifier));

              // These are set to true if either the allow access or deny access rights are set
              bool allowAccess = false;
              bool denyAccesss = false;

              foreach (FileSystemAccessRule currentRule in acl)
              {
            // If the current rule applies to the current user
            if (user.User.Equals(currentRule.IdentityReference) || principal.IsInRole((SecurityIdentifier)currentRule.IdentityReference))
            {
              if (currentRule.AccessControlType.Equals(AccessControlType.Deny))
              {
            if ((currentRule.FileSystemRights & rights) == rights)
            {
              denyAccesss = true;
            }
              }
              else if (currentRule.AccessControlType.Equals(AccessControlType.Allow))
              {
            if ((currentRule.FileSystemRights & rights) == rights)
            {
              allowAccess = true;
            }
              }
            }
              }

              return allowAccess & !denyAccesss;
        }
开发者ID:proNestorAps,项目名称:HostsFileManager,代码行数:34,代码来源:AccessControl.cs

示例7: base

	public FileSystemAuditRule
				(String identity, FileSystemRights fileSystemRights,
				 InheritanceFlags inheritanceFlags,
				 PropagationFlags propagationFlags, AuditFlags auditFlags)
			: base(IdentityReference.IdentityFromName(identity),
				   (int)fileSystemRights, false, inheritanceFlags,
				   propagationFlags, auditFlags) {}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:FileSystemAuditRule.cs

示例8: AddFileSecurity

        public static void AddFileSecurity(string fileName, string WindowsAccount, FileSystemRights rights, AccessControlType accessControlType)
        {
            FileSecurity fSecurity = File.GetAccessControl(fileName);
            fSecurity.AddAccessRule(new FileSystemAccessRule(WindowsAccount, rights, accessControlType));
            File.SetAccessControl(fileName, fSecurity);

        }
开发者ID:alexndrejoly,项目名称:csharpmlib,代码行数:7,代码来源:Security.cs

示例9: AddDirectorySecurity

		private static void AddDirectorySecurity(string folderName, string account, FileSystemRights rights, InheritanceFlags inheritance, PropagationFlags propogation, AccessControlType controlType)
		{
			DirectoryInfo directoryInfo = new DirectoryInfo(folderName);
			DirectorySecurity accessControl = directoryInfo.GetAccessControl();
			accessControl.AddAccessRule(new FileSystemAccessRule(account, rights, inheritance, propogation, controlType));
			directoryInfo.SetAccessControl(accessControl);
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:InstanceStorePermission.cs

示例10: base

	public FileSystemAccessRule
				(String identity, FileSystemRights fileSystemRights,
				 InheritanceFlags inheritanceFlags,
				 PropagationFlags propagationFlags, AccessControlType type)
			: base(IdentityReference.IdentityFromName(identity),
				   (int)fileSystemRights, false, inheritanceFlags,
				   propagationFlags, type) {}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:FileSystemAccessRule.cs

示例11: FileAccessDenier

 public FileAccessDenier(FileInfo file, FileSystemRights rights)
 {
     this.file = file;
     this.access = this.file.GetAccessControl();
     this.denial = new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name, rights, AccessControlType.Deny);
     this.access.AddAccessRule(this.denial);
     this.file.SetAccessControl(this.access);
 }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:8,代码来源:FileAccessDenier.cs

示例12: ReplacePermissions

 static void ReplacePermissions(string filepath, WellKnownSidType sidType, FileSystemRights allow)
 {
     FileSecurity sec = File.GetAccessControl(filepath);
     SecurityIdentifier sid = new SecurityIdentifier(sidType, null);
     sec.PurgeAccessRules(sid); //remove existing
     sec.AddAccessRule(new FileSystemAccessRule(sid, allow, AccessControlType.Allow));
     File.SetAccessControl(filepath, sec);
 }
开发者ID:moacs,项目名称:DDnsSharp,代码行数:8,代码来源:ProjectInstaller.cs

示例13: AddAccessRule

 /// <summary>
 /// Add an access rule to a folder
 /// </summary>
 /// 
 /// <param name="Path">Folder path</param>
 /// <param name="User">UNC path to user profile ex. Environment.UserDomainName + "\\" + Environment.UserName</param>
 /// <param name="Rights">Desired file system rights</param>
 /// <param name="Access">Desired level of access</param>
 public static void AddAccessRule(string Path, string User, FileSystemRights Rights, AccessControlType Access)
 {
     // Get a DirectorySecurity object that represents the current security settings
     System.Security.AccessControl.DirectorySecurity sec = System.IO.Directory.GetAccessControl(Path);
     // Add the FileSystemAccessRule to the security settings
     FileSystemAccessRule accRule = new FileSystemAccessRule(User, Rights, Access);
     sec.AddAccessRule(accRule);
 }
开发者ID:modulexcite,项目名称:CEX,代码行数:16,代码来源:DirectoryTools.cs

示例14: HasFilePermissions

    private static bool HasFilePermissions(string path, IdentityReference identity, FileSystemRights permissions)
    {
      var dirInfo = new FileInfo(path);
      var dirSecurity = dirInfo.GetAccessControl(AccessControlSections.All);
      AuthorizationRuleCollection rules = dirSecurity.GetAccessRules(true, true, typeof(NTAccount));

      return HasPermissions(rules, identity, permissions);
    }
开发者ID:alienlab,项目名称:Database-Management-Tool,代码行数:8,代码来源:SecurityProvider.cs

示例15: CheckAccessRight

 public static bool CheckAccessRight(DirectoryInfo directory, FileSystemRights right)
 {
     var user = WindowsIdentity.GetCurrent();
     var p = new WindowsPrincipal(user);
     AuthorizationRuleCollection acl =
     directory.GetAccessControl().GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier));
     return CheckAccessRight(user, p, acl, right);
 }
开发者ID:howej,项目名称:dotnetage,代码行数:8,代码来源:FileUtility.cs


注:本文中的FileSystemRights类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。