title: How can I get admin permissions to delete a file/folder?
body: <p>I'm writing a program to delete a file or folder from my PC, but it seems that I can't get all the permissions to delete it.</p>
  
  <p>Is there anyway to remove all the permissions from a file/folder, to make it possible to be deleted?</p>
  
  <p>My code is:</p>
  
  <pre><code>//for each file in my filepath
  foreach (string ficheiro in caminhoFicheiros)
  {
      string deletar = "Deleting: ";
      meuProgresso.Visible = true;
      meuProgresso.Increment(1);
      listBox.Items.Add(deletar + ficheiro.Substring(tamanho, ficheiro.Length - tamanho));
      //tamanho do ficheiro
  
      long length = new System.IO.FileInfo(ficheiro).Length;
      //lbMostrarItems.SelectedIndex = lbMostrarItems.Items.Count - 1;
  
      // instead of doing a try catch, i want to be able to delete the file 
      // just by getting users permission.
      try
      {
          File.Delete(ficheiro);
          listBox.Items.Add("Deleted with sucess!");
      }
      catch (IOException)
      {
          Thread.Sleep(0);
      }
      // i can´t delete the folder because i don´t have permissions.
      catch (UnauthorizedAccessException)
      {
          File.Delete(ficheiro);
      }
  
      somarTamanho += length;
  }
  </code></pre>
  
  <p>I just want to get users permissions and be able to delete files with that permission.</p>