Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I would like to get picture box image name in c#.net
Posted
Updated 21-Feb-16 3:56am
Comments
Kenneth Haugland 8-Aug-12 1:48am    
Then set it then with the Name="Something" ?!? You are have to be more specific about what you want.
Sergey Alexandrovich Kryukov 8-Aug-12 2:07am    
Makes no sense at all. And I bet you don't really need it. Moreover, most likely, you don't even need PictureBox -- it is more abused than used.
--SA

If your image is saved in your computer then shows in pictureBox, this code will be helpful.

If you got the address of image shown in pictureBox, you can use below code to get the file name.

C#
string address = @"C:\mydir\myfile.jpg";
string result;

result = Path.GetFileName(address);


And if you don't have the address of image in pictureBox, you can use this method to get fileAddress:
C#
PictureBox.ImageLocation();

Then use the Path.GetFileName() method.
 
Share this answer
 
v2
If you mean "I want to get the file name for the Image in a PictureBox", then you can't, unless you have previously saved it.
An Image doesn't refer back to it's source file, because it doesn't necessarily come from a source file in the first place - it could be camera sourced, desktop snapshot, drawn on a new bitmap, or taken from a video file.

Additionally, an Image does not have a Name property, because it can't be displayed directly - it is not derived from Control.
It does however have a Tag property, that you could set with a name when you create the Image.
 
Share this answer
 
Comments
Kenneth Haugland 8-Aug-12 2:22am    
Good answer, thank you. a 5
OriginalGriff 8-Aug-12 2:49am    
You're 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