ive created a new picturebox with the image to be directed from my directory.

but it came be the case that the directory path will always be on my desktop.

how do i make the path not hard-coded?

pictureBox = new PictureBox();
pictureBox.Image = Image.FromFile(@"D:\Documents and Settings\12344\Desktop\Model Products 40x40 v2\Model Products 40x40\CCTV\CCTV1Button.jpg");


this shld not be the case. it shld not be hard-coded. the directory might not be in the place where i start the program.

could someone help and tell me how to set the directory path name when i had already pasted the whole image folder into my program's directory?


thank u. appreciated.

Recommended Answers

All 3 Replies

there are quite a few ways to do this, simplest

string path =  Application.StartupPath;
//This gets the directory the application was started from.

And more complicated, but many people will tell you this is the only correct way, I argue against that. but it certainly does work also.

string correctPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

okay, but how do u direct to a particular jpeg in the directory ?

*sigh*

string path =  Application.StartupPath;
string subfolder = @"\Images\";
string imagefilename = "myjpeg.jpg";

pictureBox.Image = Image.FromFile(path + subfolder + imagefilename);
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.