i-Thomas
asked on
Problems with Direct / Relative Paths: File not found exception
Hi Experts!
I have an urgent problem:
I try to load an image with relative path to my Release or after installation with relative path to my Program installation folder, but I always get an System.Reflection.TargetIn vocationEx ception in my .exe
public Image Play_n = Image.FromFile(@"\buttons\ play_n.jpg ");
public Image Play_n = Image.FromFile("\buttons\\ play_n.jpg ");
both versions do not work.
What can be the reason?
The folder "buttons" is located in the project folder under bin\release\buttons on the same level as my .exe
Do I have to make some additional settings in the IDE so that relative paths are recognized?
What means do I have to detect, which actual path is built from the relative path?
Thank you very much in advance for helping!
I have an urgent problem:
I try to load an image with relative path to my Release or after installation with relative path to my Program installation folder, but I always get an System.Reflection.TargetIn
public Image Play_n = Image.FromFile(@"\buttons\
public Image Play_n = Image.FromFile("\buttons\\
both versions do not work.
What can be the reason?
The folder "buttons" is located in the project folder under bin\release\buttons on the same level as my .exe
Do I have to make some additional settings in the IDE so that relative paths are recognized?
What means do I have to detect, which actual path is built from the relative path?
Thank you very much in advance for helping!
The relative paths are taken from the current folder. So you need to change the folder first:
Directory.CurrentDirectory = Application.StartupPath;
public Image Play_n = Image.FromFile(@"buttons\p lay_n.jpg" );
Directory.CurrentDirectory
public Image Play_n = Image.FromFile(@"buttons\p
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CurrentDirectory can be another directory. For example make a shortcut and inside the shortcut properties you can give another directory to be the "startup directory". For Windows services the startup directory is always System32.
Sorry for the property/method mistake.
Absolute paths are not possible when you have different installations of a program.
Sorry for the property/method mistake.
Absolute paths are not possible when you have different installations of a program.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi both of you!
Thank you very much again for helping me out!!
I hope my splitting of points is ok for both of you...
Thank you very much again for helping me out!!
I hope my splitting of points is ok for both of you...
yes i ve found the error..
simple:
public Image Play_n = Image.FromFile(@"\buttons\
the path is wrong it shoud be @".\buttons\play_n.jpg"
because @"\buttons\play_n.jpg" would be absolute (like linux)
so you can write @".\buttons\play_n.jpg" or @"buttons\play_n.jpg"
I hope this solves your problem. Ive tested it and it worked for me
mfg WebSpecials