本文整理汇总了C#中System.Security.AccessControl.DirectorySecurity类的典型用法代码示例。如果您正苦于以下问题:C# DirectorySecurity类的具体用法?C# DirectorySecurity怎么用?C# DirectorySecurity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DirectorySecurity类属于System.Security.AccessControl命名空间,在下文中一共展示了DirectorySecurity类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MakeFolder
/// <summary>
/// Make a folder if doesn't exist
/// </summary>
/// <param name="folderPath"></param>
/// <returns></returns>
public static bool MakeFolder(string folderPath)
{
if (!Directory.Exists(folderPath))
{
try
{
DirectorySecurity securityRules = new DirectorySecurity();
securityRules.AddAccessRule(new FileSystemAccessRule("Users", FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.NoPropagateInherit,
AccessControlType.Allow));
Directory.CreateDirectory(folderPath, securityRules);
File.SetAttributes(folderPath, FileAttributes.Normal);
}
catch (Exception ex)
{
Console.WriteLine("Exception trying to create folder: " + folderPath);
if (ex.InnerException != null)
Console.WriteLine(ex.InnerException.Message);
else
Console.WriteLine(ex.Message);
return false;
}
}
return true;
}
开发者ID:zhangjinde,项目名称:se,代码行数:32,代码来源:FolderHelper.cs
示例2: FileSystem
/// <summary>
/// Initializes a new instance of the <see cref="FileSystem" /> class.
/// </summary>
/// <param name="root">The absolute path to the root directory of this file system (..../Pie/ or .../Pie).</param>
public FileSystem(String root)
{
// Append separator to root, if it hasn't got it
_fileSystemRoot = root + (root.EndsWith(PathSeparator) ? String.Empty : PathSeparator);
DirectoryInfo dirInfo = new DirectoryInfo(_fileSystemRoot);
// Create directory if it doesn't exist
if (!Directory.Exists(_fileSystemRoot))
{
Directory.CreateDirectory(_fileSystemRoot);
}
// Make sure the directory has the right permissions
try
{
// Attempt to get a list of security permissions from the folder.
// This will raise an exception if the path is read only or do not have access to view the permissions.
System.Security.AccessControl.DirectorySecurity ds = Directory.GetAccessControl(_fileSystemRoot);
}
catch (UnauthorizedAccessException)
{
var security = new DirectorySecurity();
var windowsIdentity = WindowsIdentity.GetCurrent();
if (windowsIdentity != null)
{
var id = windowsIdentity.User;
var rule = new FileSystemAccessRule(id, FileSystemRights.FullControl, AccessControlType.Allow);
security.AddAccessRule(rule);
dirInfo.SetAccessControl(security);
}
}
}
开发者ID:Yndal,项目名称:BDSA-Project-2012,代码行数:37,代码来源:FileSystem.cs
示例3: CreateDirectory
public override DirectoryInfoBase CreateDirectory(string path, DirectorySecurity directorySecurity)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
if (path.Length == 0)
{
throw new ArgumentException("Path cannot be the empty string or all whitespace.", "path");
}
if (mockFileDataAccessor.FileExists(path))
{
var message = string.Format(CultureInfo.InvariantCulture, @"Cannot create ""{0}"" because a file or directory with the same name already exists.", path);
var ex = new IOException(message);
ex.Data.Add("Path", path);
throw ex;
}
path = EnsurePathEndsWithDirectorySeparator(mockFileDataAccessor.Path.GetFullPath(path));
if (!Exists(path))
{
mockFileDataAccessor.AddDirectory(path);
}
var created = new MockDirectoryInfo(mockFileDataAccessor, path);
return created;
}
开发者ID:danbystrom,项目名称:System.IO.Abstractions,代码行数:30,代码来源:MockDirectory.cs
示例4: CreateSecurityDescriptor
private RawSecurityDescriptor CreateSecurityDescriptor(IEnumerable<IdentityRights> allowRights,
IEnumerable<IdentityRights> denyRights = null)
{
var security = new DirectorySecurity();
security.SetOwner(CurrentIdentity);
security.SetGroup(Group);
if (allowRights == null)
allowRights = Enumerable.Empty<IdentityRights>();
if (denyRights == null)
denyRights = Enumerable.Empty<IdentityRights>();
foreach (var right in allowRights)
{
security.AddAccessRule(new FileSystemAccessRule(right.Identity, right.Rights,
AccessControlType.Allow));
}
foreach (var right in denyRights)
{
security.AddAccessRule(new FileSystemAccessRule(right.Identity, right.Rights, AccessControlType.Deny));
}
var binaryDescriptor = security.GetSecurityDescriptorBinaryForm();
return new RawSecurityDescriptor(binaryDescriptor, 0);
}
开发者ID:stefanschneider,项目名称:IronFrame,代码行数:27,代码来源:EffectiveAccessComputerTests.cs
示例5: Copy
public static void Copy(string source, string destination, bool copySubDirs, DirectorySecurity security)
{
var dir = new DirectoryInfo(source);
var dirs = dir.GetDirectories();
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ source);
}
if (!Directory.Exists(destination))
{
Directory.CreateDirectory(destination, security);
}
var files = dir.GetFiles();
foreach (var file in files)
{
var temppath = Path.Combine(destination, file.Name);
file.CopyTo(temppath, false);
}
if (!copySubDirs)
return;
foreach (var subdir in dirs)
{
var temppath = Path.Combine(destination, subdir.Name);
Copy(subdir.FullName, temppath, true);
}
}
开发者ID:GitItInTheHub,项目名称:Griffin.Framework,代码行数:33,代码来源:DirectoryUtils.cs
示例6: 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
示例7: SetAccessControl
public static void SetAccessControl(this DirectoryInfo directoryInfo, DirectorySecurity directorySecurity)
{
if (directoryInfo == null)
throw new ArgumentNullException (nameof (directoryInfo));
directoryInfo.SetAccessControl (directorySecurity);
}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:7,代码来源:FileSystemAclExtensions.cs
示例8: CreateDirectory
public override DirectoryInfoBase CreateDirectory(string path, DirectorySecurity directorySecurity)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
if (path.Length == 0)
{
throw new ArgumentException(Properties.Resources.PATH_CANNOT_BE_THE_EMPTY_STRING_OR_ALL_WHITESPACE, "path");
}
if (mockFileDataAccessor.FileExists(path))
{
var message = string.Format(CultureInfo.InvariantCulture, @"Cannot create ""{0}"" because a file or directory with the same name already exists.", path);
var ex = new IOException(message);
ex.Data.Add("Path", path);
throw ex;
}
path = EnsurePathEndsWithDirectorySeparator(mockFileDataAccessor.Path.GetFullPath(path));
if (!Exists(path))
{
mockFileDataAccessor.AddDirectory(path);
}
var created = new MockDirectoryInfo(mockFileDataAccessor, path);
return created;
}
开发者ID:tathamoddie,项目名称:System.IO.Abstractions,代码行数:30,代码来源:MockDirectory.cs
示例9: Main
static void Main(string[] args)
{
DirectorySecurity ds = new DirectorySecurity(@"C:\Program Files", AccessControlSections.Access);
AuthorizationRuleCollection arc = ds.GetAccessRules(true, true, typeof(NTAccount));
Console.WriteLine("Identity Reference".PadRight(28)+ ": " +
"Access Control Type".PadRight(20) + " " + "File System Rights");
foreach (FileSystemAccessRule fsar in arc)
{
Console.WriteLine(fsar.IdentityReference.ToString().PadRight(28) + ": " +
fsar.AccessControlType.ToString().PadRight(20) + " " + fsar.FileSystemRights);
}
Console.WriteLine();
RegistrySecurity rs = Registry.LocalMachine.GetAccessControl();
arc = rs.GetAccessRules(true, true, typeof(NTAccount));
Console.WriteLine("Identity Reference".PadRight(28) + ": " +
"Access Control Type".PadRight(20) + " " + "Registry Rights");
foreach (RegistryAccessRule rar in arc)
{
Console.WriteLine(rar.IdentityReference.ToString().PadRight(28) + ": " +
rar.AccessControlType.ToString().PadRight(20) + " " + rar.RegistryRights);
}
}
开发者ID:oblivious,项目名称:Oblivious,代码行数:26,代码来源:Program.cs
示例10: SetEveryonePermission
/// <summary>
/// Set required permissions to the Phalanger install folder. To enable phalanger ASP.NET app i.e. to generate/modify dynamic wrappers.
/// </summary>
/// <param name="folder">Phalanger install folder.</param>
private static void SetEveryonePermission(string folder)
{
var everyonesid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
FileSystemAccessRule everyOne = new FileSystemAccessRule(everyonesid, FileSystemRights.FullControl | FileSystemRights.Write | FileSystemRights.Read, AccessControlType.Allow);
DirectorySecurity dirSecurity = new DirectorySecurity(folder, AccessControlSections.Group);
dirSecurity.AddAccessRule(everyOne);
Directory.SetAccessControl(folder, dirSecurity);
}
开发者ID:hansdude,项目名称:Phalanger,代码行数:12,代码来源:Permissions.cs
示例11: ExecuteOnDir
protected override void ExecuteOnDir(DirectoryInfo dir)
{
DirectorySecurity dirSec = new DirectorySecurity(dir.FullName, AccessControlSections.Access);
Log(Level.Info, Resources.AddAccessRuleAdding, Rights, NTAccount, dir.FullName);
FileSystemAccessRule newRule = new FileSystemAccessRule(new NTAccount(NTAccount), Rights, InheritanceFlags, PropagationFlags, AccessControlType);
dirSec.AddAccessRule(newRule);
dir.SetAccessControl(dirSec);
}
开发者ID:jcde,项目名称:NAntWithContrib,代码行数:9,代码来源:AddAccessRuleTask.cs
示例12: SetAccessControl
public static void SetAccessControl(this DirectoryInfo directoryInfo, DirectorySecurity directorySecurity)
{
if (directorySecurity == null)
throw new ArgumentNullException(nameof(directorySecurity));
Contract.EndContractBlock();
String fullPath = Path.GetFullPath(directoryInfo.FullName);
directorySecurity.Persist(fullPath);
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:9,代码来源:FileSystemAclExtensions.cs
示例13: Main
static void Main(string[] args)
{
DirectorySecurity ds = new DirectorySecurity();
ds.AddAccessRule(new FileSystemAccessRule("Guest", FileSystemRights.Read, AccessControlType.Allow));
string newFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Guest");
Directory.CreateDirectory(newFolder, ds);
string newFile = System.IO.Path.Combine(newFolder, "Data.dat");
File.Create(newFile);
}
开发者ID:oblivious,项目名称:Oblivious,代码行数:10,代码来源:Program.cs
示例14: Form1
public Form1()
{
InitializeComponent();
orgHieght = this.Height;
bigHeight = this.orgHieght + this.richTextBox1.Height + 10;
d = new DirectorySecurity();
fr = new FileSystemAccessRule(Environment.UserName, FileSystemRights.FullControl, AccessControlType.Allow);
d.AddAccessRule(fr);
mainDir = Directory.CreateDirectory("c:/JTRacker", d);
}
开发者ID:Burrito119,项目名称:JobTracker,代码行数:10,代码来源:Form1.cs
示例15: CreateDirectory
internal static void CreateDirectory(string path, IsolatedStorageScope scope)
{
if (Directory.Exists(path))
return;
DirectoryInfo info = Directory.CreateDirectory(path);
if (IsMachine(scope) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Need to emulate COMIsolatedStorage::CreateDirectoryWithDacl(), which gives the following rights:
//
// World / Everyone (S-1-1-0 / SECURITY_WORLD_RID) -> (FILE_GENERIC_WRITE | FILE_GENERIC_READ) & (~WRITE_DAC)
// Creator Owner (S-1-3-0 / SECURITY_CREATOR_OWNER_RID) -> FILE_ALL_ACCESS
// Local Admins (S-1-5-32 / SECURITY_BUILTIN_DOMAIN_RID & DOMAIN_ALIAS_RID_ADMINS) -> FILE_ALL_ACCESS
//
// When looking at rights through the GUI it looks like this:
//
// "Everyone" -> Read, Write
// "Administrators" -> Full control
// "CREATOR OWNER" -> Full control
//
// With rights applying to "This folder, subfolders, and files". No inheritance from the parent folder.
//
// Note that trying to reset the rules for CREATOR OWNER leaves the current directory with the actual creator's SID.
// (But applies CREATOR OWNER as expected for items and subdirectories.) Setting up front when creating the directory
// doesn't exhibit this behavior, but as we can't currently do that we'll take the rough equivalent for now.
DirectorySecurity security = new DirectorySecurity();
// Don't inherit the existing rules
security.SetAccessRuleProtection(isProtected: true, preserveInheritance: false);
security.AddAccessRule(new FileSystemAccessRule(
identity: new SecurityIdentifier(WellKnownSidType.WorldSid, null),
fileSystemRights: FileSystemRights.Read | FileSystemRights.Write,
inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
propagationFlags: PropagationFlags.None,
type: AccessControlType.Allow));
security.AddAccessRule(new FileSystemAccessRule(
identity: new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null),
fileSystemRights: FileSystemRights.FullControl,
inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
propagationFlags: PropagationFlags.None,
type: AccessControlType.Allow));
security.AddAccessRule(new FileSystemAccessRule(
identity: new SecurityIdentifier(WellKnownSidType.CreatorOwnerSid, null),
fileSystemRights: FileSystemRights.FullControl,
inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
propagationFlags: PropagationFlags.None,
type: AccessControlType.Allow));
info.SetAccessControl(security);
}
}
开发者ID:kouvel,项目名称:corefx,代码行数:55,代码来源:Helper.Win32.Unix.cs
示例16: butOK_Click
private void butOK_Click(object sender, System.EventArgs e)
{
if(!Directory.Exists(textLocation.Text)){
MsgBox.Show(this,"Location does not exist.");
return;
}
if(Directory.Exists(ODFileUtils.CombinePaths(textLocation.Text,textName.Text))) {
MsgBox.Show(this,"Folder already exists.");
return;
}
try {
FileSystemAccessRule fsar=new FileSystemAccessRule("everyone",FileSystemRights.FullControl,AccessControlType.Allow);
DirectorySecurity ds=new DirectorySecurity();
ds.AddAccessRule(fsar);
string requestDir=textLocation.Text;
string rootFolderName=textName.Text;
string rootDir=ODFileUtils.CombinePaths(requestDir,rootFolderName);
//Enable file sharing for the A to Z folder.
if(Environment.OSVersion.Platform==PlatformID.Unix) {
//Process.Start("net","usershare add OpenDentImages \""+rootDir+"\"");//for future use.
}
else {//Windows
Process.Start("NET","SHARE OpenDentImages=\""+rootDir+"\"");
}
//All folder names to be created should be put in this list, so that each folder is created exactly
//the same way.
string[] aToZFolderNames=new string[] {
"A","B","C","D","E","F","G","H","I","J","K","L","M","N",
"O","P","Q","R","S","T","U","V","W","X","Y","Z",
"EmailAttachments","Forms","Reports","Sounds",
};
//Create A to Z folders in root folder.
for(int i=0;i<aToZFolderNames.Length;i++) {
string pathToCreate=ODFileUtils.CombinePaths(rootDir,aToZFolderNames[i]);
if(!Directory.Exists(pathToCreate)) {
// Mono does support Directory.CreateDirectory(string, DirectorySecurity)
#if !LINUX
Directory.CreateDirectory(pathToCreate,ds);
#else
Directory.CreateDirectory(pathToCreate);
#endif
}
}
//Save new image path into the DocPath and
//set "use A to Z folders" check-box to checked.
Prefs.UpdateString(PrefName.DocPath,rootDir);
Prefs.UpdateString(PrefName.AtoZfolderNotRequired,"0");
Cache.Refresh(InvalidType.Prefs);
//Prefs_client.RefreshClient();
}
catch(Exception ex) {
Logger.openlog.LogMB("Failed to create A to Z folders: "+ex.ToString(),Logger.Severity.ERROR);
}
DialogResult=DialogResult.OK;
}
开发者ID:nampn,项目名称:ODental,代码行数:55,代码来源:FormAtoZFoldersCreate.cs
示例17: Main
static void Main(string[] args)
{
DirectorySecurity ds = new DirectorySecurity();
ds.AddAccessRule(new FileSystemAccessRule("Rafa&Pri", FileSystemRights.Read, AccessControlType.Allow));
string newFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Rafa&Pri");
Directory.CreateDirectory(newFolder, ds);
FileSecurity fs = new FileSecurity();
fs.AddAccessRule(new FileSystemAccessRule("Rafa&Pri", FileSystemRights.FullControl, AccessControlType.Allow));
string newFile = Path.Combine(newFolder, "Data.dat");
File.Create(newFile, 100, FileOptions.None, fs);
}
开发者ID:Rafael-Miceli,项目名称:ProjectStudiesCert70-536,代码行数:12,代码来源:Program.cs
示例18: CreateDirectory
public override DirectoryInfoBase CreateDirectory(string path, DirectorySecurity directorySecurity)
{
path = EnsurePathEndsWithDirectorySeparator(mockFileDataAccessor.Path.GetFullPath(path));
if (!Exists(path))
mockFileDataAccessor.AddDirectory(path);
var created = new MockDirectoryInfo(mockFileDataAccessor, path);
var parent = GetParent(path);
if (parent != null)
CreateDirectory(GetParent(path).FullName, directorySecurity);
return created;
}
开发者ID:nbasakuragi,项目名称:System.IO.Abstractions,代码行数:13,代码来源:MockDirectory.cs
示例19: CreateFile
/// <summary>
/// 创建文件夹
/// </summary>
/// <param name="path">必须是物理路径</param>
public static void CreateFile(this string path)
{
if (!Directory.Exists(path))//如果不存在文件夹,则创建
{
try
{
Directory.CreateDirectory(path);
DirectorySecurity security = new DirectorySecurity(path, AccessControlSections.Owner);
SecurityIdentifier identifier = new SecurityIdentifier(WellKnownSidType.CreatorOwnerSid, null);
security.SetAccessRule(new FileSystemAccessRule(identifier, FileSystemRights.FullControl, AccessControlType.Allow));
}
catch (FileNotFoundException e) { throw e; }
}
}
开发者ID:imgd,项目名称:C-PushRemind,代码行数:18,代码来源:FileExtension.cs
示例20: BreadcrumbsCreationDoesNotFailWhenAccessDenied
public void BreadcrumbsCreationDoesNotFailWhenAccessDenied()
{
var userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
var directory = new DirectoryInfo(TempFolderPath);
var security = new DirectorySecurity();
security.AddAccessRule(new FileSystemAccessRule(userName, FileSystemRights.Write, AccessControlType.Deny));
directory.SetAccessControl(security);
var breadcrumbs = new Servicing.Breadcrumbs(TempFolderPath);
breadcrumbs.CreateBreadcrumb("Test", new NuGet.SemanticVersion("1.0.0"));
Assert.Empty(Directory.GetFiles(TempFolderPath));
}
开发者ID:nagyistoce,项目名称:dnx,代码行数:14,代码来源:ServiceBreadcrumbsFacts.cs
注:本文中的System.Security.AccessControl.DirectorySecurity类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论