questions about paths

Hammy

Freshman
Joined
Jan 15, 2003
Messages
27
Location
Ontario, Canada
Hi all,

I am new to VB and am working through some vb.net exercises. I some of them I place a picturebox control on my form, then with various events set theimage using system.drawing.image.fromfile method. When using this method, they have me place a hard-coded path to the images.

My head got to thinking, when I build a deployment solution for these projects down the road, if these images have a hard coded path, is it not going to cause errors unless the user were to install the application in the EXACT same location as my working solution? I may be jumping the gun and this will end up being covered, but I am the type that likes to find solutions when I see a potential problem.

I was playing around with setting the path to something like (Application.StartupPath & "\images\image.bmp") for example. Thinking that when I create the deployment I would be sure to include tohe images and create an image directory in the deployment setup.

What is the best way to code the path for these types of images so they will still be displayed after deployment regardless of the user's installation choices? Is this method I am playing around with a good one?

TIA
Hammy
 
Application.StartupPath gets the start up path value in the short cut file if you launch it with a shortcut this could mean you'd be look in a directory anywhere on the harddrive.

Try creating a simple program that just shows a messagebox telling you the startup path, create a shortcut to it and change the Startup Path Property in the shortcut to anywhere else and see what the program says.
 
I did as you said, and changed the "start in" property (left the target the same) and the msgbox still displayed the proper path the .exe file was in.

If I run the program directly (not using a shortcut) it still displays the proper path. If I move the program to a new folder, it still displays the proper path.

If I change the target, then it would cause a problem......the program wouldn't load.

I am not sure exactly what your after....are you saying IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) is the best way to go?

From VB Studio.Net

Application.StartupPath Property

Gets the path for the executable file that started the application.

From that I am assuming that as long as I refer to my images folder relative to that path, and create my deployment solution with the directories in that same relative position it should work (I may be missing something, that's why I'm asking). The user should then be able to install anywhere they wish and the relative paths should be correct?

Please clarify,
Hammy
 
Last edited:
That is correct. As long as all of your files are stored within your
program's directory (or sub-directories of it), you can access them
using Application.Startup path.
 
I think the application.startup is relative to the EXE that started. Meaning, if you have a DLL in a different location and you use Application.Startup, the originating EXE's path will be returned. Generally, this is what you would want anyhoo.

-ner
 
Visual Basic:
IO.Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly.FullName).FullName
Will return the directory that the program is actually located in,
rather than where it was started from.
 
Back
Top