Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am new to wpf. I have a button if clicked shows a openfiledialogbox we can select image and display on the grid.it is displaying only image I want to display image name along with image on a textblock. I dont want to display the entire path.

Can anyone help me please how to do this in wpf...?

Thanks..
Posted
Updated 29-Jun-11 23:45pm
v3

If you only want to display the name of the image, you can use it this way:

C#
string path = @"C:\MyImage.jpeg";
string fileName = System.IO.Path.GetFileName(path);  //Returns MyImage.jpeg
string fileNameWOExtension = System.IO.Path.GetFileNameWithoutExtension(path); //Returns MyImage

textBlock1.Text = fileName;


Hope it helped.
 
Share this answer
 
Comments
KiranBabu M 30-Jun-11 5:22am    
Thanks tarun
i got it..
Tarun.K.S 30-Jun-11 5:51am    
You're welcome.
[no name] 30-Jun-11 5:46am    
Good Call Tarun.
[no name] 30-Jun-11 5:46am    
My 5 too.
Tarun.K.S 30-Jun-11 5:51am    
Thanks Rama.
You need to put a textblock on your form to hold this text. Use the Path.GetFilename method in System.IO to turn your path in to a filename. All of this is pretty straightforward, if you have a decent book or two, or learn to use google. I suggest for someone at your level, the best way to learn is to buy a book a work through it, not rely on questions in forums. Forums work better when you know some basic things.
 
Share this answer
 
Comments
Tarun.K.S 30-Jun-11 5:50am    
Doesn't deserve a 2. Countered.
Christian Graus 30-Jun-11 6:23am    
Thank you. The only difference between my answer and the one that got accepted, is that I try to make people think for themselves, to filter out the people too lazy to try to write their own code.

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