Javatpoint Logo
Javatpoint Logo

C# Program to Demonstrate the Use of FullName Property

C# is one of the most powerful and multi-faceted programming languages used by many developers to create different types of applications. Another critical element of working with C# is acquiring knowledge about properties that various classes have and how they can be used to improve the performance of your programs.

In this post, we will look at the FullName property in C# and demonstrate its use through syntax, code samples, and outputs.

Understanding the FullName Property

  • In C#, the FullName property is frequently found alongside classes involved in file and directory manipulation. It is employed to obtain the complete path of a file or directory along with its name.
  • This property makes getting the complete location of a file or directory easy for developers who may need to work with elements from the file system.

Syntax of the FullName Property:

  • Syntax for accessing the FullName property is to create an instance of a class such as FileInfo or DirectoryInfo and then use dot notation for that.

Here's a generic representation of the syntax:

// For FileInfo

// For DirectoryInfo

  • Instantiate the respective class (FileInfo or DirectoryInfo).
  • Supply the file or directory path as a parameter to the constructor.
  • Retrieve the FullName property using dot notation.

Illustrative Code with Explanation

An example scenario will elucidate the usage of the FullName property. In this instance, we'll construct a basic C# console application showcasing how to leverage the FullName property to retrieve the full path of a file.


Full path of the file: C:\SampleFiles\example.txt


  • File Path Specification

The program initiates by defining a file path ("C:\SampleFiles\example.txt"), representing the location of a specific file on the system.

  • FileInfo Object Instantiation

An instance of the FileInfo class, named fileInfo, is created using the specified file path. This class is instrumental in providing detailed information about the specified file.

  • Retrieval of FullName Property

The program accesses the FullName property of the FileInfo object. This property returns the complete path, encompassing both the directory and file name, for the designated file.

  • String Assignment

The resulting full path is assigned to a string variable, denoted as fileFullName.

  • Console Output

The program communicates the outcome by utilizing Console.WriteLine() to print the full path of the file to the console.

  • Displaying the Result

Upon execution, the program outputs the complete path of the specified file ("C:\SampleFiles\example.txt") to the console.

In the given C# code excerpt, the program is crafted to exemplify the practical application of the FileInfo class and its FullName property for retrieving and presenting the complete path of a specified file. The sequence initiates with the explicit definition of a file path, followed by the instantiation of a FileInfo object, denoted as fileInfo, corresponding to the provided path. This object functions as a conduit for extracting detailed information about the designated file.

The focal point of the operation involves accessing the FullName property of the FileInfo instance, yielding the comprehensive path encompassing both the directory and file name. Subsequently, this information is assigned to a string variable named fileFullName. The program concludes by conveying the acquired full path through console output, employing the Console.WriteLine() method.

In the course of execution, the console output discloses the entire file path, providing developers with a streamlined approach to obtain thorough file information. This succinct yet efficient code snippet serves as a foundational illustration of how C#'s FileInfo class can be adeptly used, showcasing the language's prowess in simplifying interactions with file-related functionalities.

In summary, the presented C# code offers a demonstrative instance of harnessing the FileInfo class and its FullName property, underscoring the language's effectiveness in streamlining file system operations. Developers can gain valuable insights into proficient file path retrieval, augmenting their comprehension of C#'s capabilities in managing tasks related to files.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA