Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a PictureBox on one of my windows form, now I would like to get the name of the image which is already set in the PictureBox.
I tried:
C#
string imagepath = pictureBox3.ImageLocation.ToString();

//and to get only name of image.

string picname = imagepath.Substring(imagepath.LastIndexOf('\\'));
Posted
Updated 11-Nov-11 22:20pm
v3
Comments
Sam Path 12-Nov-11 4:34am    
Elaborate your question?

1 solution

This may not work - it depends on how you have loaded the image into the PictureBox.
If you fix the image at design time, by setting an source in the properties pane, then there is no URL to fetch.
If you load the image from a resource, it may not work either.
If you load the PictureBox.Image property at runtime from an Image or Bitmap, then there is no URL to fetch.

The only instance I can see where ImageLocation contains anything useful, is when you use PictureBox.Load method.

What are you trying to achieve, that you think this would help?
 
Share this answer
 
Comments
choudhary.sumit 12-Nov-11 4:41am    
ok. i just want to insert the image name in database along with the rest of the registration fields.
OriginalGriff 12-Nov-11 4:54am    
That will only work if you use the PictureBox.Load method. Personally, I would save the file name at the point at which I got it, so I would not have to be reliant on using a PictureBox for display - I would get better separation between my Data Layer and my Presentation Layer that way.
Sergey Alexandrovich Kryukov 12-Nov-11 22:20pm    
My 5, especially for the above comment.
--SA

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