Hammy Posted January 16, 2003 Posted January 16, 2003 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 Quote
Leaders Iceplug Posted January 16, 2003 Leaders Posted January 16, 2003 From a tutorial: IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) returns the name of the application's path. Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Hammy Posted January 16, 2003 Author Posted January 16, 2003 Thanks for the info....is there a way I could view that tutorial? Hammy Quote
Leaders Iceplug Posted January 16, 2003 Leaders Posted January 16, 2003 Yes. It's just over in the Tutors Corner here Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Machaira Posted January 16, 2003 Posted January 16, 2003 I would just use Application.StartupPath as you posted. Quote Here's what I'm up to.
AndreRyan Posted January 17, 2003 Posted January 17, 2003 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. Quote .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?
Hammy Posted January 17, 2003 Author Posted January 17, 2003 (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 January 17, 2003 by Hammy Quote
*Experts* Volte Posted January 17, 2003 *Experts* Posted January 17, 2003 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. Quote
*Experts* Nerseus Posted January 17, 2003 *Experts* Posted January 17, 2003 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 Quote "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* Volte Posted January 17, 2003 *Experts* Posted January 17, 2003 IO.Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly.FullName).FullNameWill return the directory that the program is actually located in, rather than where it was started from. Quote
Hammy Posted January 17, 2003 Author Posted January 17, 2003 So I am gathering that there are several ways to accomplish the same goal :) ? Hammy Quote
*Gurus* divil Posted January 17, 2003 *Gurus* Posted January 17, 2003 Yes, there are. I use: System.IO.Path.GetDirectoryName(Application.ExecutablePath) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Nerseus Posted January 17, 2003 *Experts* Posted January 17, 2003 I use Environment.CurrentDirectory. -ner Quote "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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.