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


Top 5 Contributors of the Month
david stephan

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

 Subscribe to Code Snippets

Get File name from full file path

Posted By:Amit Mehra       Posted Date: February 07, 2010    Points: 10    Category: File Operation    URL: http://www.dotnetspark.com  

This code sample will return the file name from file path. Suppose if you have the full file path and you wanted to get only file name this method of Path class.
 

This code sample will return the file name from file path. Suppose if you have the full file path and you wanted to get only file name this method of Path class will give you the file name and removed the folder and sub folder name.

Path class is available in System.IO so do not forget to include the namespace.

string fileName = Path.GetFileName(@"c:\MyFolder\MyFile.txt");

Response.Write(fileName);

And the result will be

MyFile.txt


     

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