c# Detect if a file is able to be deleted : <p>i am trying to complete the simple task of detecting if a file is able to be deleted, for example: if a <code>.dll</code> is being used by another program you are not able to delete the <code>.dll</code> - this is what i want to be able to detect. Well yeah hopefully that makes sense.</p>

<p>So far I've tried the following with no luck:</p>

<pre><code>try
{
    System.IO.File.Delete(@"C:\Program Files\MyTestFiles\testing.dll");
}
catch
{
    Console.WriteLine("Unable to delete file");
}
</code></pre>

<p>and i've tried:</p>

<pre><code>System.IO.File.Delete(@"C:\Program Files\MyTestFiles\testing.dll");
if(File.Exists(@"C:\Program Files\MyTestFiles\testing.dll"))
{
    Console.WriteLine("Error: Unable to delete file");
}
else
{
    Console.WriteLine("Successfully deleted file!");
}
</code></pre>
