title: Sometimes can rename, remove a folder; sometimes cannot
body: <p>In my website project. I need to rename or remove some folder by code. </p>
  
  <p>Sometimes I can do all of that, but sometimes I cannot with error: <code>Access to the path is denied</code></p>
  
  <p>Try to find to solution on Google. May be, there are two reason:</p>
  
  <ol>
  <li>The permisstion of that Folder</li>
  <li>Some subFolder or some file in that Folder that's being held open.</li>
  </ol>
  
  <p>Try to check:</p>
  
  <ol>
  <li>Right click on Folder-> Properties--> Security: if this is the right way to check the permission, the Folder allowes every action (read, write....)</li>
  <li>There are no file, no subfolder of that Folder is opened. </li>
  </ol>
  
  <p>Why? I still dont understant why sometimes I can rename folder but sometimes I cannot.</p>
  
  <p>Help!! I need your opinions!!!</p>
  
  <p>UPDATE:</p>
  
  <p>take a look at my code above:
  I want to rename the a folder with the new name inputed in a Textbox <code>txtFilenFolderName</code>:</p>
  
  <pre><code>protected void btnUpdate_Click(object sender, EventArgs e)
  {
     string[] values = EditValue;
     string oldpath = 
         values[0];// = "D:\\C#Projects\\website\\Lecturer\\giangvien\\New folder"
  
     string oldName = values[2]; //= New Folder
  
     string newName = txtFilenFolderName.Text; //= New Folder1
     string newPath = string.Empty;
  
     if (oldName != newName)
     {
        newPath = oldpath.Replace(oldName, newName);
        Directory.Move(oldpath, newPath);
     }
     else
     {
        lblmessage2.Text = "New name must not be the same as the old ";
     }
  </code></pre>
  
  <p>}</p>
  
  <p>Try to debug: </p>
  
  <pre><code>oldpath = "D:\\C#Projects\\website\\Lecturer\\giangvien\\New folder"
   oldName = New Folder
  newName= New Folder1
  newpath = "D:\\C#Projects\\website\\Lecturer\\giangvien\\New folder1"
  </code></pre>
  
  <p>Everything seems right, but I when I click on buton Edit ---> rename---> Update---> an error occur: <code>Access to the path is denied D:\\C#Projects\\website\\Lecturer\\giangvien\\New folder</code></p>
  
  <p>Help!</p>