
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# Program to get the last access time of a file
To get the last access time of a file in C#, use the LastAccessTime() method.
For this, use the FileInfo as well as DateTime classes.Create an object of each −
FileInfo file = new FileInfo("new.txt"); DateTime dt = file.CreationTime; dt = file.LastAccessTime;
Let us see the complete code −
Example
using System.IO; using System; public class Program { public static void Main() { using (StreamWriter sw = new StreamWriter("quiz.txt")) { sw.WriteLine("Quizzes!"); } FileInfo file = new FileInfo("quiz.txt"); // last access time DateTime dt = file.LastAccessTime; Console.WriteLine(dt); } }
Output
9/5/2018 5:21:43 AM
- Related Articles
- C# Program to get the last write time of a file
- How to check file last access time using Python?
- How to check the Date and time of Access (last modified) of a File using Java?
- How to get file last modified time in Java?
- How do you get the last access (and/or write) time of a MySQL database?
- Get the creation time of a file in C#
- C# program to get the extension of a file in C#
- Get the date/time of the last change to a MySQL database?
- C# Program to get information about a file
- C# program to get the file name in C#
- C# Program to get the absolute value of the time
- C++ Program to get the last item from the array
- C# program to get the last element from an array
- C++ Program to get the last given number of items from the array
- Program to get the last element from an array using C#

Advertisements