How to

get file name from path

Published: 22. January 2009 | Updated: 22. January 2009
License: Microsoft Public License (MS-PL)
Categories: File system » Files
Tags: C# File System Windows
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.IO;

Code

string fileName = Path.GetFileName(@"C:\Test\text.txt");

// or 

FileInfo info = new FileInfo(@"C:\Test\text.txt");
string fileName = info.Name;
Send us feedback about this snippet »



Related Snippets: