Click here to Skip to main content
15,891,597 members
Home / Discussions / C#
   

C#

 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
Luc Pattyn11-Jan-10 13:08
sitebuilderLuc Pattyn11-Jan-10 13:08 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
aespielberg11-Jan-10 13:24
aespielberg11-Jan-10 13:24 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
aespielberg11-Jan-10 13:34
aespielberg11-Jan-10 13:34 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
Luc Pattyn11-Jan-10 13:50
sitebuilderLuc Pattyn11-Jan-10 13:50 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
Daniel Grunwald12-Jan-10 6:20
Daniel Grunwald12-Jan-10 6:20 
QuestionHow do I set the "Apply onto" option in NTFS file security rights using c#? Pin
arnold_w11-Jan-10 9:12
arnold_w11-Jan-10 9:12 
AnswerRe: How do I set the "Apply onto" option in NTFS file security rights using c#? [modified] Pin
arnold_w12-Jan-10 2:52
arnold_w12-Jan-10 2:52 
GeneralRe: How do I set the "Apply onto" option in NTFS file security rights using c#? Pin
batrado_®8-Feb-10 1:42
batrado_®8-Feb-10 1:42 
Thanks for the wonderful post
I added another parameter to your setDirectoryPermission (..) function - ApplyTo. It is equivalent to "Apply theese permissions to objects and / or containers within this container only" checkbox in the object-tab, which is also the option ApplyOnto .. I think that the code is finished
For this purpose, I changed PropagationFlags with two-dimensional array and I added one more enum "ApplyTo"
Here's how it looks:

public struct PermissionInfo
{
	public FileSystemRights fileSystemRight;
	public AccessControlType allowOrDeny;
	public PermissionInfo(FileSystemRights fileSystemRight_, AccessControlType allowOrDeny_)
	{
		fileSystemRight = fileSystemRight_;
		allowOrDeny = allowOrDeny_;
	}
}

public enum ApplyOnto
{
	THIS_FOLDER_ONLY = 0,
	THIS_FOLDER_AND_SUBFOLDERS_AND_FILES = 1,
	THIS_FOLDER_AND_SUBFOLDERS = 2,
	THIS_FOLDER_AND_FILES = 3,
	FILES_AND_SUBFOLDERS_ONLY = 4,
	SUBFOLDERS_ONLY = 5,
	FILES_ONLY = 6
}

public enum ApplyTo
{
	ObjectAndChilds = 0,
	ThisObjectOnly = 1
}

private static InheritanceFlags[] inheritanceFlags = new InheritanceFlags[]
{
	InheritanceFlags.None,                                              // THIS_FOLDER_ONLY  
	InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, //THIS_FOLDER_AND_SUBFOLDERS_AND_FILES
	InheritanceFlags.ContainerInherit,                                  // THIS_FOLDER_AND_SUBFOLDERS
	InheritanceFlags.ObjectInherit,                                     // THIS_FOLDER_AND_FILES
	InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, // FILES_AND_SUBFOLDERS_ONLY
	InheritanceFlags.ContainerInherit,                                  // SUBFOLDERS_ONLY
	InheritanceFlags.ObjectInherit                                      // FILES_ONLY
};

private static PropagationFlags[,] propagationFlags = new PropagationFlags[,]
{  {PropagationFlags.None,
	   PropagationFlags.NoPropagateInherit},         						// THIS_FOLDER_ONLY
	{PropagationFlags.None,
		PropagationFlags.NoPropagateInherit},        						// THIS_FOLDER_AND_SUBFOLDERS_AND_FILES
	{PropagationFlags.None,
		PropagationFlags.NoPropagateInherit},        						// THIS_FOLDER_AND_SUBFOLDERS
	{PropagationFlags.None,
		PropagationFlags.NoPropagateInherit},        						// THIS_FOLDER_AND_FILES
	{PropagationFlags.InheritOnly,
		PropagationFlags.InheritOnly| PropagationFlags.NoPropagateInherit},	// FILES_AND_SUBFOLDERS_ONLY
	{PropagationFlags.InheritOnly,
		PropagationFlags.InheritOnly| PropagationFlags.NoPropagateInherit}, // SUBFOLDERS_ONLY
	 {PropagationFlags.InheritOnly,
		 PropagationFlags.InheritOnly| PropagationFlags.NoPropagateInherit} // FILES_ONLY
};


public static void setDirectoryPermission(string directory, string user, PermissionInfo[] permissionInfo, ApplyOnto applyOnto, ApplyTo applyTo)
{
	DirectoryInfo myDirectoryInfo = new DirectoryInfo(directory);
	DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
	for (int i = 0; i < permissionInfo.Length; i++)
	{
		myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(
			user,
			permissionInfo[i].fileSystemRight,
			inheritanceFlags[(int)applyOnto],
			propagationFlags[(int)applyOnto, (int)applyTo],
			permissionInfo[i].allowOrDeny
			));
	}
	myDirectoryInfo.SetAccessControl(myDirectorySecurity);
}

QuestionSend video capture over LAN Pin
shutupsquare11-Jan-10 8:58
shutupsquare11-Jan-10 8:58 
AnswerRe: Send video capture over LAN Pin
Alex Manolescu11-Jan-10 9:49
Alex Manolescu11-Jan-10 9:49 
QuestionFinding * characters in a string Pin
sleepyman11-Jan-10 8:52
sleepyman11-Jan-10 8:52 
AnswerRe: Finding * characters in a string Pin
Alex Manolescu11-Jan-10 9:31
Alex Manolescu11-Jan-10 9:31 
GeneralRe: Finding * characters in a string Pin
PIEBALDconsult11-Jan-10 14:54
mvePIEBALDconsult11-Jan-10 14:54 
AnswerRe: Finding * characters in a string Pin
Luc Pattyn11-Jan-10 9:48
sitebuilderLuc Pattyn11-Jan-10 9:48 
GeneralRe: Finding * characters in a string Pin
sleepyman12-Jan-10 8:11
sleepyman12-Jan-10 8:11 
AnswerRe: Finding * characters in a string Pin
PIEBALDconsult11-Jan-10 14:52
mvePIEBALDconsult11-Jan-10 14:52 
Questiongetting a specific tag out of a web page Dom info [modified] Pin
manustone11-Jan-10 6:39
manustone11-Jan-10 6:39 
AnswerRe: getting a specific tag out of a web page Dom info Pin
manustone12-Jan-10 20:41
manustone12-Jan-10 20:41 
QuestionMerge strings and overwrite certain characters based on a filter Pin
AndreasLa11-Jan-10 6:18
AndreasLa11-Jan-10 6:18 
AnswerRe: Merge strings and overwrite certain characters based on a filter Pin
Dave Kreskowiak11-Jan-10 6:32
mveDave Kreskowiak11-Jan-10 6:32 
AnswerRe: Merge strings and overwrite certain characters based on a filter Pin
Saksida Bojan11-Jan-10 6:38
Saksida Bojan11-Jan-10 6:38 
Questionwriting xml using datagrid Pin
naghoumeh1411-Jan-10 6:04
naghoumeh1411-Jan-10 6:04 
QuestionGetting all data from commandline app Pin
blaatschapje11-Jan-10 5:31
blaatschapje11-Jan-10 5:31 
AnswerRe: Getting all data from commandline app Pin
Alan N11-Jan-10 6:22
Alan N11-Jan-10 6:22 
AnswerRe: Getting all data from commandline app Pin
Luc Pattyn11-Jan-10 7:01
sitebuilderLuc Pattyn11-Jan-10 7:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.