I am trying to write a program in Visual Basic that will erase a file in use. The code below can erase images, music and videos in use but you can not delete documents.
Is there any way to make the program detect the process and stop it so you can delete the file or get priority over it and delete it?
My code so far:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 'Borrar archivo'
If String.IsNullOrEmpty(TextBox1.Text) Then 'Evita el error de Visual Basic donde el archivo esta vacio'
MsgBox("No hay un archivo a seleccionar, por favor busque uno", vbCritical)
Else
Dim result As Integer = MessageBox.Show("¿Esta seguro que quiere borrar el archivo? No se podrá recuperar el archivo sin un programa especial", "¿Seguro?", MessageBoxButtons.YesNo) 'Evita que el usuario borre un archivo que no queria borrar por error'
If result = DialogResult.No Then
MsgBox("Archivo no borrado", vbInformation, "Resultado")
ElseIf result = DialogResult.Yes Then
IO.File.Delete(TextBox1.Text$)
MsgBox("El archivo fue borrado con éxito", vbInformation, "Resultado")
End If
End If
End Sub