Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a windows application in C#. I have picture (pro.png) in debug file and I load it to picturebox by this code:
C#
String FileName = "pro.png";
this.pictureBox1.Image = Image.FromFile(FileName);


When I published the project it generates an error in the application .EXE that it can't see the image. What is the solution please?
If I create a folder (PIC) in my solution and then add the picture (user.png) to it how can I put this image into the pictureBox.

Thanks in advance!

[Added code tags]
Posted
Updated 21-Jan-11 4:07am
v4
Comments
Manfred Rudolf Bihy 21-Jan-11 9:25am    
Why did you delete you first question where you asked exactly the same question. You already had gotten an answer so what were you thinking when you deleted your question. This kind of behavior is not tolerated on CP. I see you changed the tagging. So I guess that gives me an answer to what I asked of you in a comment to your question. It is a WinForm application and not ASP.NET as you tagged it last time.

I see though that my edit of your question has at least made it into the "new" question, but again you ignored the use of code tags. (rectified)

1 solution

I reckon your question is whether you can get away with not providing the full path. If so, no. It's always best to provide the full path to the image.

You will find that sometimes it works okay even if you don't specify the full path, but don't depend on this behavior. The current directory, search directories etc. are not predictable at runtime, so you need to specify the full path always.

[Edit]
----------

In response to your comment, here's how you can get the path to the image folder in your application directory (using your example folder and image names).

C#
string imagePath = Path.Combine(Path.GetDirectoryName(
    Assembly.GetExecutingAssembly().Location), @"pic\pro.png");
 
Share this answer
 
v3
Comments
MohammedSabry 21-Jan-11 10:06am    
ok if i add folder in my solution it`s name is (PIC) and then i add (pro.png) in this folder
whats the full path will be ??
Nish Nishant 21-Jan-11 10:18am    
Updated my answer.
MohammedSabry 21-Jan-11 11:02am    
thanks for your help
Nish Nishant 21-Jan-11 11:04am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900