944,029 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 14552
  • C# RSS
Jun 26th, 2005
0

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

Expand Post »
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!!!!!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
raybristol is offline Offline
1 posts
since Jun 2005
Jun 28th, 2005
0

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

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\" />
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
senexom is offline Offline
54 posts
since Jun 2005
Jul 1st, 2005
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mainline is offline Offline
1 posts
since Jul 2005
Jul 4th, 2005
0

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

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BSTRhino is offline Offline
1 posts
since Jun 2005
Jul 4th, 2005
0

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

Application.ExecutablePath <-- Path + executable name
Application.StartupPath <-- Only path
Reputation Points: 13
Solved Threads: 6
Junior Poster in Training
r0ckbaer is offline Offline
55 posts
since Dec 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Displaying an Excel document in a windows application
Next Thread in C# Forum Timeline: C# Winform WebClient identification





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC