Getting the latest file modified from Azure Blob
Each IListBlobItem is going to be a CloudBlockBlob, a CloudPageBlob, or a CloudBlobDirectory.
After casting to block or page blob, or their shared base class CloudBlob
(preferably by using the as
keyword and checking for null), you can access the modified date via blockBlob.Properties.LastModified
.
Note that your implementation will do an O(n) scan over all blobs in the container, which can take a while if there are hundreds of thousands of files. There's currently no way of doing a more efficient query of blob storage though, (unless you abuse the file naming and encode the date in such a way that newer dates alphabetically come first). Realistically if you need better query performance I'd recommend keeping a database table handy that represents all the file listings as rows, with things like an indexed DateModified column to search by and a column with the blob path for easy access to the file.
How to retrieve latest file from SharePoint to blob using logic app?
Follow the workaround
You can use the below Trigger & Connector
- Sharepoint (
Trigger
) - When a file is created or modified in a folder
You can use this connector to select and get the exact Directory to fetch the recent Modified/Created File.
- Azure Blob Storage (
Connector
)- Create Blob (V2)
Use this connector to create a blob.
Result
Modified file fetched and added in a Blob
Refer here for more information
Updated Answer
Here is the list of available directories in SharePoint that will be shown in a SharePoint Trigger. You can select according to your requirement.
Get last modified date of latest file in a storage account
Finally got the answer(simply last modified date of all files,not the specific latest file).
//Code to get the last modified date
CloudBlockBlob blockBlob = Container.GetBlockBlobReference(blobName);
blockBlob.FetchAttributes();
var lastModifiedDate = blockBlob.Properties.LastModified;
Console.WriteLine(lastModifiedDate);
How to get files modified today from Azure Blob Storage
Just add a Where
clauses and compare to DateTime.Today
:
var blockbob = container.ListBlobs().OfType<CloudBlockBlob>()
.Where(m => m.Properties.LastModified.Value.Date == DateTime.Today).ToList().First();
I added a working example to my GitHub repository that uses dotnet core with the latest WindowsAzure.Storage SDK:
public async Task RetrieveBlobsModifiedTodayAsync()
{
var container = _blobClient.GetContainerReference(_storageAccount.ContainerName);
BlobContinuationToken blobContinuationToken = null;
do
{
var results = await container.ListBlobsSegmentedAsync(null, blobContinuationToken);
var blobs = results.Results.OfType<CloudBlockBlob>()
.Where(b => b.Properties.LastModified != null && b.Properties.LastModified.Value.Date == DateTime.Today);
blobContinuationToken = results.ContinuationToken;
foreach (var item in blobs)
{
Console.WriteLine(item.Uri);
}
} while (blobContinuationToken != null); // Loop while the continuation token is not null.
}
Related Topics
Truncate Two Decimal Places Without Rounding
How to Set a Cookie on Httpclient'S Httprequestmessage
How to Download a File from a Url in C#
How to Format a String as a Telephone Number in C#
C# String to Hex , Hex to Byte Conversion
Regex to Match Alphanumeric and Spaces
Map a Property to List of Object Using Automapper Createmap
How to Change a Image on a Button Using Windows Forms
How to Remove Time Portion of Date in C# in Datetime Object Only
Client Specific Role Based Authentication
How to Check If a Socket Is Connected/Disconnected in C#
Getting the Latest File Modified from Azure Blob
Localhost Port Is Changing in Visual Studio 2017
How to Count Number of Visitors for Website in ASP.NET C#
How to Determine If a Json Object Contains Only a Specific Key
How to Display Values Only Upto 2 Decimal Places
How to Cast Object to List<Object> and Turn It into an Array