\n
\nNow 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?
\nvar blobClient = new BlobClient("conn-string", "upload", "Data.zip");\nawait DownloadFromStream(blobClient);\n\n\npublic static async Task DownloadFromStream(BlobClient blobClient)\n {\n int i = 0;\n var stream = await blobClient.OpenReadAsync(new BlobOpenReadOptions(false));\n using ZipArchive archive = new ZipArchive(stream);\n foreach (ZipArchiveEntry entry in archive.Entries.OrderBy(x => x.LastWriteTime))\n {\n if (entry.Name.StartsWith("XXX_TS_"))\n {\n i++;\n Console.WriteLine(i);\n Console.WriteLine(entry.Name);\n }\n }\n }\n
\n","author":{"@type":"Person","name":"user584018"},"upvoteCount":0,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"I have tried in the below way, and it worked for me.
\nIn Azure portal.
\nCode snippet
\nvar blobClient = new BlobClient("ConnectionString", "ContainerName", "Data.zip");\nawait DownloadFromStream(blobClient);\n\npublic static async Task DownloadFromStream(BlobClient blobClient)\n {\n var stream = await blobClient.OpenReadAsync(new BlobOpenReadOptions(false));\n ZipArchive archive = new ZipArchive(stream);\n List<string> sFileslist = new List<string>();\n foreach (ZipArchiveEntry entry in archive.Entries.OrderBy(x => x.LastWriteTime))\n {\n if (entry.Name.Contains("_TS_"))\n {\n string[] strFileTokens = entry.Name.Split('_');\n sFileslist.Add(strFileTokens[2]);\n } \n }\n string maxValue = sFileslist.Max();\n Console.WriteLine(maxValue);\n }\n\n
\nFetched the Latest file as output.
\nReputation: 11364
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);
}
}
}
Upvotes: 0
Views: 72
Reputation: 1514
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.
Upvotes: 1