IMAGE PATH

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I've some problem by getting files in my application path: I've to run the
following
instruction

MyButton.Image = Image.FromFile(MyImagePath));

MyImagePath should be the path where to find the image and I want to
instantiate it dinamically like this:

string MyImagePath = Path.GetFullPath("image.ico")

The result of MyImagePath is
"C:\test\MyApp\MyApp.Presentation\bin\Debug\image.ico" but it is NOT correct:
the file image.ico is in the following path
"C:\test\MyApp\MyApp.Presentation\image\image.ico".

Can anybody help me to find a solution? How can I get the correct path by
using a method like Path.GetFullPath()? I precise that it doesn't work this
solution:

string MyImagePath = Path.GetFullPath("..\..\image\image.ico")

because of the release version!!

Please help me, thenks
Siu
 
Hi Siu,

Why don't you add an entry to the configuration file specifying the path?
Simply, accessing it using the configuration api and append the image file
name.
Benefit: you can change the path without recompiling the application.

my 2 cents
Gerd
 
Hi Gerd,
thanks for your answer... I know that it works by writing the path in the
configuration file, but do I have to write all the path in the File System?
Like this: C:\pippo\pluto\minni\

thanks again
 
Not necessarily if you define the root once.
There a lot of options.
- You may set the root directory by setting the current directory using
Environment.CurrentDirectory.
- You may set the root directory only once in the application configuration.
Other settings may consider this setting.
- You may define an environment variable containing the root path. Access it
again with Environment class using the GetEnvornmentVariables collection
- You may use a special folder with Environment.GetSpecialFolder() using one
of the Environment.SpecialFolder enumeration.
 
Back
Top