.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get filename with extension from given full file path

Posted By:Amit Mehra       Posted Date: March 21, 2013    Points: 40    Category: File Operation    URL: http://www.dotnetspark.com  

Get filename from given input string as file path in C# using Path class in provided in .NET Framework
 

Sometimes when doing the programming we have to find the file name from the given string. Classic ways we have to parse the file path and get the last array.

But in .NET Framework we have Path class and some built in method to find the filename from given file path

Path class is available in system.IO namespace.

below in the code to get the file name with extension.

Full Code in C#


string fileName = Path.GetFileName(@"C:\File Directory\fileName.txt");

Output will be


fileName.txt

Hope this will help

Happy Coding


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend