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!!!!!

Recommended Answers

All 4 Replies

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 <add key="root" value="C:\mystuff\" />

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.

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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.