In a down stream system Every day
one data folder is created within folder Data
and files are generated over time within a sub folder TS
and finally it's zip with name Data.zip
and uploaded to azure blob by customer.
Now I am downloading the zip file and trying to find out the one file which has max date/time. using below code I am able to print all files name inside the zip file, but how to get (print) only the file with max date/time?
var blobClient = new BlobClient("conn-string", "upload", "Data.zip");
await DownloadFromStream(blobClient);
public static async Task DownloadFromStream(BlobClient blobClient)
{
int i = 0;
var stream = await blobClient.OpenReadAsync(new BlobOpenReadOptions(false));
using ZipArchive archive = new ZipArchive(stream);
foreach (ZipArchiveEntry entry in archive.Entries.OrderBy(x => x.LastWriteTime))
{
if (entry.Name.StartsWith("XXX_TS_"))
{
i++;
Console.WriteLine(i);
Console.WriteLine(entry.Name);
}
}
}
I have tried in the below way, and it worked for me.
In Azure portal.
Code snippet
var blobClient = new BlobClient("ConnectionString", "ContainerName", "Data.zip");
await DownloadFromStream(blobClient);
public static async Task DownloadFromStream(BlobClient blobClient)
{
var stream = await blobClient.OpenReadAsync(new BlobOpenReadOptions(false));
ZipArchive archive = new ZipArchive(stream);
List<string> sFileslist = new List<string>();
foreach (ZipArchiveEntry entry in archive.Entries.OrderBy(x => x.LastWriteTime))
{
if (entry.Name.Contains("_TS_"))
{
string[] strFileTokens = entry.Name.Split('_');
sFileslist.Add(strFileTokens[2]);
}
}
string maxValue = sFileslist.Max();
Console.WriteLine(maxValue);
}
Fetched the Latest file as output.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.