hello friends,
I have one locked folder in C:\b. There are many files in that folder. So now,I want to move all the files from locked folder to other folder.
My lock folder code is here:
private void Permissionbtn_Click_1(object sender, EventArgs e)
{
DirectoryInfo myDirectoryInfo = new DirectoryInfo(textBox1.Text);
DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
string User = System.Environment.UserDomainName + "\\" + comboBox1.SelectedItem.ToString();
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User,
FileSystemRights.Read, InheritanceFlags.ObjectInherit,PropagationFlags.None,AccessControlType.Deny));
myDirectoryInfo.SetAccessControl(myDirectorySecurity);
MessageBox.Show("Permissions Altered Successfully");
}
Here is my move_files code:
string sourcePath = @"C:\b\";
string destinationPath = @"\\server\t\";
string[] files = System.IO.Directory.GetFiles(sourcePath);
foreach (string s in files)
{
var fileName = Path.GetFileName(s);
sourceFile = System.IO.Path.Combine(sourcePath, fileName);
destFile = System.IO.Path.Combine(destinationPath, fileName);
File.Move(sourceFile, destFile);
}
When I going to run move_files code it will throws the "Access to the path 'C:\b\' is denied.". How to do this? please help me out.