Scenario: Download Script
You are working as C# developer and you need to get the latest file from a folder. There could be different reasons you want to get the latest file, You might get the files in a folder and you need to get the get the latest to load to SQL server Table.
Below sample script can be used to get the latest file from folder. I have saved the latest file name in variable and printed on screen by using Console.Write() method.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace TechBrothersIT.com_CSharp_Tutorial { class Program { static void Main(string[] args) { //Provide folder path from which you like to get latest file string Folder = @"C:\Source\"; var files = new DirectoryInfo(Folder).GetFiles("*.*"); string latestfile = ""; DateTime lastModified = DateTime.MinValue; foreach (FileInfo file in files) { if (file.LastWriteTime > lastModified) { lastModified = file.LastWriteTime; latestfile = file.Name; } } //To see the value of latest variable, You can remove both lines Console.Write("Latest File Name: "+latestfile); Console.ReadLine(); } } }
How to find the most recent file in a directory by using C# |
This is an important article. I read like this type of article only. You mentioned more important points about technology. Thankyou.
ReplyDeletecore java training in chennai
core java course
core java Training in Adyar
c++ courses in chennai
C++ Training
javascript training in chennai
Appium Training in Chennai
JMeter Training in Chennai
Good article, can you please write about how to load/import data from rest api or api into sql, please. Thanks
ReplyDeleteSuch a nice blog. I got very much information and it is very useful for us. For More details, visit us.
ReplyDeletec++ read file line by line
Mua vé máy bay tại Aivivu, tham khảo
ReplyDeletevé máy bay đi Mỹ Vietnam Airline
khi nào có chuyến bay từ mỹ về việt nam
vé máy bay nhật việt vietjet
lich bay tu duc ve viet nam
chuyến bay từ canada về việt nam
Có chuyến bay từ Hàn Quốc về Việt Nam không
giá khách sạn cách ly ở hà nội
thanks for sharing this useful content. There are 23 classic design patterns, which are described in the original book, Design Patterns: Elements of Reusable Object-Oriented Software.
ReplyDeletecode