Path.GetFileName method in C#

In this article I will explain Path.GetFileName method in C#.
  • 9902

Introduction

C# path is a name of a directory which identify a unique location of a file in a file system. A path of a file system is expressed in a string of character. Path.GetFileName Method method is a type of c# path. Path.GetFileName Method returns the file name and extension of the specified path string.. Path.GetFileName finds a file name and extension from a path. We look at this .NET framework method.

Example

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

class Program

{

    static void Main()

    {

        string fileName = @"C:\rahul\rahulpics\myfile.ext";

        string path = @"C:\rahul\rahulpics\";

        string result;

        result = Path.GetFileName(fileName);

        Console.WriteLine("GetFileName('{0}') returns '{1}'",

        fileName, result);

        result = Path.GetFileName(path);

        Console.WriteLine("GetFileName('{0}') returns '{1}'", path, result);

        Console.ReadLine();

    }

} 


The output of the following program

Clipboard115.jpg
  

© 2020 DotNetHeaven. All rights reserved.