Create New Account
help
folderName)) return false ; if (! Directory . Exists (folderName)) return false ; var directory = new DirectoryInfo (folderName); var directorySecurity = directory . GetAccessControl (); var rule = new FileSystemAccessRule (windowsAccountUserName, FileSystemRights .Modify, InheritanceFlags . None | InheritanceFlags .ContainerInherit | InheritanceFlags .ObjectInherit, PropagationFlags . None , AccessControlType . Allow ); directorySecurity . SetAccessRule ( rule ); directory . SetAccessControl ( directorySecurity ); return true ; } #endregion #region Grant Read Access To Folder public static bool GrantReadAccessToFolder( string windowsAccountUserName folderName)) return false ; if (! Directory . Exists (folderName)) return false ; var directory = new DirectoryInfo (folderName); var directorySecurity = directory . GetAccessControl (); var rule = new FileSystemAccessRule (windowsAccountUserName, FileSystemRights .ReadAndExecute, InheritanceFlags . None | InheritanceFlags .ContainerInherit | InheritanceFlags .ObjectInherit, PropagationFlags . None , AccessControlType . Allow ); directorySecurity . SetAccessRule ( rule ); directory . SetAccessControl ( directorySecurity ); return true ; } #endregion } Use .NET To Grant NTFS Access Rights
ControlType As AccessControlType) ' Create a new DirectoryInfoobject. Dim dInfo As New DirectoryInfo(FileName) ' Get a DirectorySecurity object that represents the ' current security settings. Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl() ' Add the FileSystemAccessRule to the security settings. dSecurity.AddAccessRule(New FileSystemAccessRule(Account, Rights, ControlType)) ' Set the new access settings. dInfo.SetAccessControl(dSecurity) End Sub anywhere on the net. . . have spent about all day now trying to Get a FileSecurity object that represents the ' current security settings. Dim fSecurity As FileSecurity = File.GetAccessControl(fileName) ' Add the FileSystemAccessRule to the security settings. Dim accessRule As FileSystemAccessRule = _ New FileSystemAccessRule(account, rights, controlType) @@@@@ fSecurity.AddAccessRule(accessRule)<- -- -HERE - -- @@@@@@@@@@ ' Set the new access settings. File.SetAccessControl(fileName, fSecurity) End Sub This is the artical that i am going along with but Server.MapPath("~ / NewFolder")) Dim dirInfo As DirectoryInfo = New DirectoryInfo(Server.MapPath("~ / NewFolder")) Dim sec As DirectorySecurity = dirInfo.GetAccessControl() Dim id As System.Security.Principal.WindowsIdentity = WindowsIdentity.GetCurrent Dim rule As New Security.AccessControl
AccessControl; using System.IO; public static bool GrantModifyAccessToFolder( string windowsAccountUserName, string folderName) { DirectoryInfo directory = null ; DirectorySecurity directorySecurity = null ; FileSystemAccessRule rule = null ; try { if (windowsAccountUserName.Length <1) { return false ; } if (folderName.Length <1) { return false ; } if (!Directory.Exists(folderName)) { return false ; } directory = new DirectoryInfo(folderName); directorySecurity = directory GetAccessControl(); rule = new FileSystemAccessRule(windowsAccountUserName, FileSystemRights.Modify, InheritanceFlags.None | InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); directorySecurity.SetAccessRule(rule); directory.SetAccessControl(directorySecurity); return true ; } catch (Exception) { throw ; } } Cassini Web Server Installation You'll want to include UltiDev
Me How To Set The Folder Permissions. THanks in Advance. You can use Addaccessrule and SetAccessControl methods of DirectoryInfo class to set the permissions to folders. see the below example: 1 retrieving the directory information 4: DirectoryInfo myDirectoryInfo = new DirectoryInfo(textBox1.Text); 5: 6: / / Get a DirectorySecurity object that represents the 7: / / current security settings. 8: DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl(); 9: string User = System.Environment.UserDomainName + " \ " + comboBox1.SelectedItem.ToString(); 10: 11: / / Add the FileSystemAccessRule to FileSystemAccessRule(User, FileSystemRights.Read, AccessControlType.Deny)); 24: 25: / / Set the new access settings. 26: myDirectoryInfo.SetAccessControl(myDirectorySecurity); 27: 28: / / Showing a Succesfully Done Message 29: MessageBox.Show(" Permissions Altered Successfully"); 30
ACL is out of order, SetAccessControl hello experts, i have a problem if i run the following code: if (Directory.Exists Propogation, AccessControlType ControlType) { / / Create a new DirectoryInfo object. DirectoryInfo dInfo = new DirectoryInfo(FileName); / / 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, Inheritance, Propogation ControlType)); / / Set the new access settings. dInfo.SetAccessControl(dSecurity); } when i run this code it throws an error. " System.InvalidOperationException: This access control