954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

hi, how to set a proper path of a image file, many thanks!

I can load a image file from a fold if I did like this:

Bitmap myBitmap3 = new Bitmap(@"C:\HEapp\images\logo.bmp");

however, this is not convenient if I move my program, so I was try to do this:

Bitmap myBitmap3 = new Bitmap(@"\images\logo.bmp");

however, it doesn't work, could anyone tell me how to do this, many thanks!!

another question, how do I export a porper exe file which can run on a computer has no framework installed?

many thanks!!!!!

raybristol
Newbie Poster
1 post since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

It needs to be an absolute path to the file, so you need to use Server.MapPath()

like so...
Bitmap myBitmap3 = new Bitmap(Server.MapPath("~/images/logo.bmp"));

(Assuming this is a web app)

if this is not a web app, and you plan on moving this around, I suggest setting a key in the config file of the root path like

senexom
Junior Poster in Training
54 posts since Jun 2005
Reputation Points: 11
Solved Threads: 0
 

If your just looking to reference a file from the current directory, you can drop the first \. @"images\logo.bmp" might be what your looking for.

mainline
Newbie Poster
1 post since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

I'm not sure if this is the question that raybristol is asking, but I do wonder, how do you get a path to the place where the EXE is located, from which you can find the folder it is in and so on? What I mean is, how could you make it so you can place the EXE anywhere, whether it be C:\My Documents\HelloWorld.exe or C:\Program Files\Hello\HelloWorld.exe and the program would still be able to find out where you put it?

BSTRhino
Newbie Poster
1 post since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

Application.ExecutablePath <-- Path + executable name
Application.StartupPath <-- Only path

r0ckbaer
Junior Poster in Training
55 posts since Dec 2003
Reputation Points: 13
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You