Skip to content
Related Articles

Related Articles

C# Program to Check the Information of the File

View Discussion
Improve Article
Save Article
  • Last Updated : 01 Nov, 2021

Given a file, now our task is to view the information of this file through C#. So to do this task we use FileInfo class. This class provides different types of properties and methods for creating, copying, deleting, opening, and moving files. It is also, used for creating FileStream objects. So here we create an object of the FileInfo class which contains the file name. 


FileInfo info = new FileInfo("C:\\sravan\\data.txt"); 


In this example, we consider a file named ” data.txt” present in the “sravan” folder in the C drive or “C:\\sravan\\data.txt”. Now with the help of this path, we will find the information of “data.txt” file using the Attributes property. This property returns an enumerated constant which is encoded as enum flag.


// C# program to display the information of file
using System;
using System.IO;
class GFG{
static void Main()
    // Get the file 
    FileInfo information = new FileInfo("C:\\sravan\\data.txt");
    // Get the file information
    FileAttributes attributes = information.Attributes;
    // Display file information
    Console.WriteLine("Attribute of the File is {0}", attributes);


Attribute of the File is Archive
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!