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


C# DirectoryInfo.GetAccessControl方法代码示例

本文整理汇总了C#中DirectoryInfo.GetAccessControl方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.GetAccessControl方法的具体用法?C# DirectoryInfo.GetAccessControl怎么用?C# DirectoryInfo.GetAccessControl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DirectoryInfo的用法示例。


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

示例1: CreateDirectory

	public static string CreateDirectory(string physicalTargetPath, string directoryName, string virtualTargetPath)
	{
		try
		{
			DirectoryInfo parentDir = new DirectoryInfo(physicalTargetPath);

			Directory.CreateDirectory(PathHelper.AddEndingSlash(physicalTargetPath, '\\') + directoryName, parentDir.GetAccessControl());
		}
		catch (DirectoryNotFoundException)
		{
			string message = string.Format("FileSystem restriction: Directory with name '{0}' is not found!", virtualTargetPath);
			return message;
		}
		catch (UnauthorizedAccessException)
		{
			string message = "FileSystem's restriction: You do not have enough permissions for this operation!";
			return message;
		}
		catch (IOException)
		{
			string message = string.Format("FileSystem restriction: The directory '{0}' cannot be created!", virtualTargetPath);
			return message;
		}

		return string.Empty;
	}
开发者ID:Bert6623,项目名称:Gedcom.Net,代码行数:26,代码来源:FileSystem.cs

示例2: CopyDirectory

	public static string CopyDirectory(string physycalSourcePath, string physicalDestPath, string virtualSourcePath, string virtualDestPath)
	{
		// Copy all files ;
		string newDirPhysicalFullPath;// Contains the physical path to the new directory ;
		DirectoryInfo dirInfoSource;
		try
		{
			dirInfoSource = new DirectoryInfo(physycalSourcePath);
			newDirPhysicalFullPath = string.Format("{0}{1}{2}", PathHelper.AddEndingSlash(physicalDestPath, '\\'), dirInfoSource.Name, "\\");

			// Else ;
			Directory.CreateDirectory(newDirPhysicalFullPath, dirInfoSource.GetAccessControl());
		}
		catch (UnauthorizedAccessException ex)
		{
			string message = "FileSystem's restriction: You do not have enough permissions for this operation!";
			return message;
		}

		// Directory is created ;

		foreach (string currentFilePath in Directory.GetFiles(physycalSourcePath))
		{
			FileInfo fileInfo = new FileInfo(currentFilePath);

			string newFilePath = newDirPhysicalFullPath + fileInfo.Name;

			try
			{
				File.Copy(currentFilePath, newFilePath);
			}

			catch (FileNotFoundException ex)
			{
				string message = string.Format("File: '{0}' does not exist!", virtualSourcePath);
				return message;
			}
			catch (UnauthorizedAccessException ex)
			{
				string message = "You do not have enough permissions for this operation!";
				return message;
			}
			catch (IOException ex)
			{
				string message = "The operation cannot be compleated";
				return message;
			}
		}

		// Copy all subdirectories ;
		foreach (string physicalCurrentSourcePath in Directory.GetDirectories(physycalSourcePath))
		{
			DirectoryInfo dirInfo = new DirectoryInfo(physicalCurrentSourcePath);
			string physicalCurrentDestPath = newDirPhysicalFullPath;// Change the name of the variable ;
			string virtualCurrentSourcePath = string.Format("{0}{1}{2}", PathHelper.AddEndingSlash(virtualSourcePath, '/'), dirInfo.Name, "/");
			string virtualCurrentDestPath = string.Format("{0}{1}{2}", PathHelper.AddEndingSlash(virtualDestPath, '/'), dirInfoSource.Name, "/");

			// Call recursively the Directory copy function ;
			string returnedError = CopyDirectory(physicalCurrentSourcePath, physicalCurrentDestPath, virtualCurrentSourcePath, virtualCurrentDestPath);
			if (returnedError != string.Empty)
			{// An error occured ;
				return returnedError;
			}
		}

		// No errors. 
		return string.Empty;
	}
开发者ID:Bert6623,项目名称:Gedcom.Net,代码行数:68,代码来源:FileSystem.cs

示例3: getitemonserver

    private void getitemonserver(string category,string item, string text)
    {
        if (category == "Files")
            {
                if (System.IO.File.Exists(item))
                {
                System.IO.File.Move(item, text);
                }
            }
            else
            {
                if (System.IO.Directory.Exists(item))
                {

                    DirectoryInfo dInfo = new DirectoryInfo(item);
                    DirectorySecurity dSecurity = dInfo.GetAccessControl();
                    string account =System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                    dSecurity.AddAccessRule(new FileSystemAccessRule(account, FileSystemRights.FullControl, AccessControlType.Allow));
                    Directory.SetAccessControl(item, dSecurity);
                    System.IO.Directory.Move(item, text);
                }
            }
    }
开发者ID:wpdildine,项目名称:wwwroot,代码行数:23,代码来源:filebrowser.ascx.cs

示例4: TestGetAccessControlSections

		[TestMethod, Ignore] //("does not work on some server/domain systems.")
		public void TestGetAccessControlSections()
		{
			var tempLongPathFilename = Path.Combine(longPathDirectory, Path.GetRandomFileName());
			Directory.CreateDirectory(tempLongPathFilename);
			try
			{
				var di = new DirectoryInfo(tempLongPathFilename);
				var security = di.GetAccessControl(AccessControlSections.Access);
				Assert.IsNotNull(security);
				Assert.AreEqual(typeof(FileSystemRights), security.AccessRightType);
				Assert.AreEqual(typeof(FileSystemAccessRule), security.AccessRuleType);
				Assert.AreEqual(typeof(FileSystemAuditRule), security.AuditRuleType);
				Assert.IsTrue(security.AreAccessRulesCanonical);
				Assert.IsTrue(security.AreAuditRulesCanonical);
				Assert.IsFalse(security.AreAccessRulesProtected);
				Assert.IsFalse(security.AreAuditRulesProtected);
				var securityGetAccessRules = security.GetAuditRules(true, true, typeof(System.Security.Principal.NTAccount)).Cast<FileSystemAccessRule>();
				Assert.AreEqual(0, securityGetAccessRules.Count());
				AuthorizationRuleCollection perm = security.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
				var ntAccount = new System.Security.Principal.NTAccount(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
				FileSystemAccessRule rule = perm.Cast<FileSystemAccessRule>().SingleOrDefault(e => ntAccount == e.IdentityReference);
				Assert.IsNotNull(rule);
				Assert.IsTrue((rule.FileSystemRights & FileSystemRights.FullControl) != 0);
			}
			finally
			{
				Directory.Delete(tempLongPathFilename);
			}
		}
开发者ID:HMartyrossian,项目名称:LongPath,代码行数:30,代码来源:DirectoryInfoTests.cs

示例5: AddDirectorySecurity

    // Adds an ACL entry on the specified directory for the specified account.
    public void AddDirectorySecurity(string DirectoryName, string Account, FileSystemRights Rights, AccessControlType ControlType)
    {
        // Create a new DirectoryInfo object.
        DirectoryInfo dInfo = new DirectoryInfo(DirectoryName);

        // Get a DirectorySecurity object that represents the
        // current security settings.
        DirectorySecurity dSecurity = dInfo.GetAccessControl();

        // Add the FileSystemAccessRule to the security settings.
        dSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType));

        // Set the new access settings.
        dInfo.SetAccessControl(dSecurity);
    }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:16,代码来源:Util.cs


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