Click here to Skip to main content
15,914,419 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
When I put
fileName=openFileDialog.FileName 
I get the full path, but I just
want the name of the file.
Posted
Comments
Tarun.K.S 14-Apr-11 3:34am    
Hey please vote and accept the answer(s) Vishal.

To get the filename, use Path.GetFileName(fileName)
 
Share this answer
 
v2
Comments
Tarun.K.S 14-Apr-11 2:48am    
That's right but walterhevedeich has a better answer.
Om Prakash Pant 14-Apr-11 2:56am    
If Framework 2.0 PRE SP1 is used then Use Path.GetFileName
else use openFileDialog.SafeFileName
Tarun.K.S 14-Apr-11 2:57am    
Oh I see, thanks for the Info.
walterhevedeich 14-Apr-11 3:13am    
He's right. SafeFileName started on .Net 3.5. I was under the assumption that OP is using that framework since his tag was VS2010. This answer is safer so Im giving it a 5. :)
Tarun.K.S 14-Apr-11 3:34am    
Sure!
fileName=openFileDialog.SafeFileName 
 
Share this answer
 
Comments
Tarun.K.S 14-Apr-11 2:47am    
Good answer! 5d!
walterhevedeich 14-Apr-11 3:09am    
Thanks.
This should help you:

C#
String theFileName = System.IO.Path.GetFileName(fileName);
 
Share this answer
 
v2

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