title: How to release a lock on a JPG file
body: <p>I'm using Microsoft.Office.Interop.MailItem to strip attachements from email, save them to disk, print them out and then delete them from disk. I'm having problems deleting JPG attachements, the file seems to have a lock,</p>
  
  <p>Here is my code for saving each attachement,</p>
  
  <pre><code>foreach (Attachment attachment in outLookMessage.Attachments)
  {
      var fileNameOnDisk = FileNameOnDisk(printFileFolder, attachment.FileName);
  
      attachment.SaveAsFile(fileNameOnDisk);
  }
  </code></pre>
  
  <p>I'm not sure why there is a lock on the JPG file. Is there any way I can release this log so that I can delete the file?</p>