Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 25-Feb-15 20:04pm
v2
Comments
BillWoodruff 26-Feb-15 2:11am    
Who locked the folder ? If you locked it, why can't you unlock it ? If somebody else locked it, why can't you get them to unlock it ?
Brinda Lakhani 26-Feb-15 3:30am    
I am developing a window application. The requirement is to move the data from the local system to server. There is some private data that generates automatically in locked folder, so no one can see those data except admin. So i want move those data to server for the admin.
Sinisa Hajnal 26-Feb-15 3:23am    
The account under which your application runs has to have rights to access and change the locked folder. If you don't own such an account, you cannot copy from locked folder (which is exactly the point of access rights)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900