Home > ASP .NET, C#, VB .NET > How to get the file name from a full file path?

How to get the file name from a full file path?

If you have a full file path like D:\My Documents\myimg.jpg and you want to get just the file name myimg.jpg, you can get it with the help of the Path class in this fashion:-

In C#

string filename = Path.GetFileName(“D:\My Documents\myimg.jpg“);
In VB .NET

Dim fileName as String = Path.GetFIleName(“D:\My Documents\myimg.jpg”)

  1. No comments yet.
  1. No trackbacks yet.