0

i crated a Picturebox in windows form.This code below is working properly

PictureBox.ImageLocation=@"C:\Users\MyPc\Desktop\Project\Image.jpg

but When i run my code in another pc the image doesn't shown cause of its directory.I have to change the pc name.How can I do this in a more general way without chancing the name?

5

1 Answer 1

0

You sould use the following method to determine the user's desktop folder:

Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

and maybe the best way for having a correct path is also using System.IO.Path.Combine() method:

PictureBox.ImageLocation = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Project", "Image.jpg"));

Not the answer you're looking for? Browse other questions tagged or ask your own question.