title: Generate a unique temporary file name with a given extension using .NET
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/581570/how-can-i-create-a-temp-file-with-a-specific-extension-with-net">How can I create a temp file with a specific extension with .net ?</a>  </p>
  </blockquote>
  
  <p>It is possible to create a temporary file in .NET by calling</p>
  
  <pre><code>string fileName = System.IO.Path.GetTempFileName();
  </code></pre>
  
  <p>This will create a file with a .TMP extension in the temporary directory.</p>
  
  <p>What if you specifically want it to have a different extension? For the sake of this example, lets say that I needed a file ending with .TR5.</p>
  
  <p>The obvious (and buggy) solution is to call</p>
  
  <pre><code>string fileName = Path.ChangeExtension(Path.GetTempFileName(), "tr5"))
  </code></pre>
  
  <p>The problems here are:</p>
  
  <ul>
  <li>It has still generated an empty file (eg tmp93.tmp) in the temp directory, which will now hang around indefinitely</li>
  <li>There is no gurantee that the resulting filename (tmp93.tr5) isn't already existing</li>
  </ul>
  
  <p>Is there a straightforward and safe way to generate a temporary file with a specific file exension?</p>