Link to my previous question, which gives background to the situation
I answered my own question above by programmatically changing images from the tempory folder where attachments are saved. This caused a new issue for me when fixing my own problem that I feel is too separate from the former.
As my program closes, I delete the images from the temporary directory. Since I have got the preview to work fine upon clicking on the different images. I get the following error when trying to close the program (the deleting of images happens on this event):
The process cannot access the file 'c:\temp\DigitalArchive\FILENAME.jpg' because it is being used by another process.
So I have attempted to resolve it by clearing the picture from the temp folder before hand via:
if (picAttachPreview.Image != null)
{
picAttachPreview.Image.Dispose();
picAttachPreview.Refresh();
}
//Runs through each file in the temporary directory and removes them to clear folder
foreach (string item in Directory.GetFiles(tempfolder))
{
File.Delete(item);
}
Edit: I feel I should show where the image is updated for reference:
if (chkAttachments.Text.Contains(".jpg"))
{
var selectedImage = chkAttachments.Text;
picAttachPreview.Image = Image.FromFile(Path.Combine(tempfolder, selectedImage));
}