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
Great Article Artificial Intelligence Projects
DeleteProject Center in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai Project Centers 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
I found Hubwit as a transparent s ite, a social hub which is a conglomerate of Buyers and Sellers who are ready to offer online digital consultancy at decent cost. gadgets for men
ReplyDelete