- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to get the last write time of a file
To get the last write time of a file in C#, use the LastWriteTime() method.
For this, use the FileInfo as well as DateTime classes.
Create an object of each −
FileInfo file = new FileInfo("amit.txt"); DateTime dt = file.CreationTime; dt = file.LastWriteTime;
Let us see the complete code −
Example
using System.IO; using System; public class Program { public static void Main() { using (StreamWriter sw = new StreamWriter("amit.txt")) { sw.WriteLine("Welcome!"); } FileInfo file = new FileInfo("amit.txt"); // file creation time DateTime dt = file.CreationTime; Console.WriteLine(dt); // last access time dt = file.LastAccessTime; Console.WriteLine(dt); // last write time dt = file.LastWriteTime; Console.WriteLine(dt); } }
Output
9/5/2018 5:17:27 AM 9/5/2018 5:17:27 AM 9/5/2018 5:17:27 AM
- Related Articles
- C# Program to get the last access time of a file
- How to get file last modified time in Java?
- Get the creation time of a file in C#
- C# program to get the extension of a file in C#
- How do you get the last access (and/or write) time of a MySQL database?
- Get the date/time of the last change to a MySQL database?
- C# Program to write an array to a file
- 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
- 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?
- C# program to get the last element from an array
- Write a program in Python to read CSV data from a file and print the total sum of last two rows
- Write a program in Python to print the first and last three days from a given time series data

Advertisements