Click here to Skip to main content
15,907,183 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All

I have a task scheduler which runs every 10 min and downloads a .log file.
I want to get the max Id from that log file and set in my code so that when next time it runs it should pick from this max id.

Can please some body help me.


Thanks
Posted
Comments
ZurdoDev 27-Jan-16 7:49am    
Sure, how can we help?
babli3 27-Jan-16 7:54am    
Hi Ryan,

public static FileInfo GetNewestFile(DirectoryInfo directory)
{
return directory.GetFiles()
.Union(directory.GetDirectories().Select(d => GetNewestFile(d)))
.OrderByDescending(f => (f == null ? DateTime.MinValue : f.LastWriteTime))
.FirstOrDefault();
}

FileInfo newestFile = GetNewestFile(new DirectoryInfo(@"C:\Log"));

This code will give me the latest downloded log file . now I have to read the contents from this file and pick the max id from it.

Can you please suggest how I can achieve this.

Thanks
ZurdoDev 27-Jan-16 7:57am    
File.ReadAllLines() will read all the lines into a string array and then you can do whatever you need to at that point.

https://msdn.microsoft.com/en-us/library/system.io.file.readalllines(v=vs.110).aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900