title: Open jpeg from byte array
body: <p>I have a program where the users can save an attachment for a contract. The attachment is saved in the database a a varbinary. The users can then view the attachment. </p>
  
  <p>I am saving the file to a temp location while they view it and then deleting the file after the process is closed. This is working fine for word and excel documents but not for jpeg files. </p>
  
  <pre><code>File.WriteAllBytes(@"C:\Temp\" + SelectedAttachment.FileName + SelectedAttachment.FileType, SelectedAttachment.FileBlob);
  
                  //open the file for viewing
                  var attachmentProcess = System.Diagnostics.Process.Start(@"C:\Temp\" + SelectedAttachment.FileName + SelectedAttachment.FileType);
                  attachmentProcess.WaitForExit();
  
  
                  //Delete temp file after user closes the file
                  File.Delete(@"C:\Temp\" + SelectedAttachment.FileName + SelectedAttachment.FileType);
  </code></pre>
  
  <p>The attachmentProcess.WaitForExit(); throws an 'System.NullReferenceException' but was not handled in user code error when the .jpeg opens. The file will open regardless of the error but does not delete upon closing the file. </p>
  
  <p>I have tried using </p>
  
  <pre><code>using (Image image = Image.FromStream(new MemoryStream(SelectedAttachment.FileBlob)))
                  {
                      image.Save("output.jpg", ImageFormat.Jpeg);  
                  }
  </code></pre>
  
  <p>but i get an error stating that " 'Image': type used in a using statement must be implicitly convertible to 'System.IDisposable'</p>
  
  <p>Is there a way to get the .jpeg file process to behave like the word or excel files or should I use the MemoryStream route and if so what am i doing wrong there?  </p>