Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Leaders
Posted

From a tutorial:

 

IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath)

 

returns the name of the application's path.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

  • Leaders
Posted
Yes. It's just over in the Tutors Corner here

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

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.

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted (edited)

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

Edited by Hammy
  • *Experts*
Posted

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.

  • *Experts*
Posted

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

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.

  • *Experts*
Posted

I use Environment.CurrentDirectory.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...