April 14th, 2011, 09:06 AM
FileNotFound Exception unhandled
Im currently trying to put a picture into my second form when a condition is met on my first form. The code i'm using is:
secondForm.pictureBox1.Image = Image.FromFile(@"ID.jpeg");
Now im getting the usual "FileNotFound Exception unhandled" error. I had this issue when taking information from text files before but that was due to poor spelling (sigh). Im getting this error with ID.jpeg but its in the same folder as the text files which now work.
I should probably check that my "file path exists" but I don't know which folder my program is searching when looking for ID.JPEG! How could I find this out?
April 14th, 2011, 11:28 AM
Re: FileNotFound Exception unhandled
The best way is to supply a full path to the file you want to open.
If the path to the image files are in a directory relative to the folder
where the app has been installed, then retrieve the app folder with GetAppFolder sample code from my reply in this post:
The use Path.Combine to form the complete path to the file.
For example, say you have an /Images folder that is a child folder of your app folder which contains the image files.
Forming the complete relative path to the file, you would end up with:
A word of warning. You can use Environment.CurrentDirectory; however, this isn't reliable because it can change at any time (i.e. any assembly can change this at will, so it may not be what you expect). Using CurrentDirectory is often a source of hard to track down bugs.
var idFile = Path.Combine( GetAppFolder( ), "Id.jpeg" );
secondForm.pictureBox1.Image = Image.FromFile( idFile );
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!