FileNotFoundException error with pictures

I a seem to be having a simple problem. In VB6 I had no problems loading pictures. when I converted the program to VB2005, it modified the code to

frmDetails.Elm_Pict.Image = System.Drawing.Image.FromFile("Pictures\h.jpg")

which is giving me a FileNotFoundException error but the path is correct!

I would greatly appriciate any advice how to fix this simple error!

Thanks,

Campsoup1988




Answer this question

FileNotFoundException error with pictures

  • smark

    Sorry I didn't mean to suggest you couldn't use relative paths, you can certainly.

    The key is understanding where that exe is actually running from and making sure the image is in the correct path. If you're debugging the project it will be under the Build Output Path which is found under the project properties. This is typically set to the Bin directory.

    So if you copy the pictures folder to the Build Output path your orginal code should work fine.

    If you want to ensure your using the correct path in your code you can always build it at run time.

    For example:

    PictureBox1.Image = System.Drawing.Image.FromFile(System.IO.Path.Combine(My.Application.Info.DirectoryPath, "Pictures\h.jpg"))



  • rwerner

    Thank You!

    That has solved the problem!

    ~~campsoup1988


  • JYB

    Try using a fully qualified path, for example "c:\pictures\h.jpg". I expect its looking for the path based on the current application location and its not finding it.

  • CSH100885

    yes, that now the picture loads, but I was hoping for a relative path so I could move the entire program from one place to the next (also because the program is currently on my pen drive which is letter E: on one comp and letter G: on the other I use, so the path would work on only one of the computers)(


  • FileNotFoundException error with pictures