Are you an adiministrator in your environment? If not you may not be able to change properties of a folder.
I am an administrator and can do everything on my machine including marking folders as readonly and vice versa except the one generated by the c# code.
-
-
// Specify the directory you want to manipulate.
-
string path = @"C:\Program Files\TestDirectory";
-
-
try
-
{
-
// Determine whether the directory exists.
-
if (Directory.Exists(path))
-
{
-
MessageBox.Show("That path exists already.");
-
return;
-
}
-
-
// Try to create the directory
-
-
DirectoryInfo di = Directory.CreateDirectory(path);
-
AddDirectorySecurity(path,"Dale", FileSystemRights.FullControl, AccessControlType.Allow);
-
-
-
MessageBox.Show("The directory was created successfully at", Directory.GetCreationTime(path).ToString());
-
-
}
-
catch (Exception ex)
-
{
-
MessageBox.Show("The process failed: {0}", e.ToString());
-
}
-
finally
-
{
-
}
-
-
public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, 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,
-
ControlType));
-
-
// Set the new access settings.
-
dI
-
«MüÑÇhK!Ñ: RIP Mike« u knw wut...i always thought dogs...lay eggs says:
-
// Set the new access settings.
-
dInfo.SetAccessControl(dSecurity);
-
-
}
-
-
the create directory is mine, the AddDirectorySecurity was a sad attempt in removing the readonly property which never worked.
I was trying to understand the overloaded function for createdirectory (path,directorysecurity) but i have been yet to figure that out.
any help form the pro's would be greatly welcomed.