0
  // Get list of all files/directories on the file share 
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["storageConnectionString"]);
            CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
            CloudFileShare fileShare = fileClient.GetShareReference(ConfigurationManager.AppSettings["shareName"]);

            var sourceName = fileShare.GetRootDirectoryReference().GetDirectoryReference((ConfigurationManager.AppSettings["sourceName"]));

            var test = sourceName.Properties.LastModified;

But sourceName.Properties.LastModified is null

even fileShare.Properties.LastModified is null

I'm getting null when I'm trying to fetch LastModified property of Azure File Share.

Neo
  • 15,491
  • 59
  • 215
  • 405

1 Answers1

2

The reason is every time you call GetRootDirectoryReference() you create a new instance of FileItem, causing in it's properties to be initialized to it's default value, just the same behavior as when using GetBlockBlobReference().

What you need to do is to call FetchAttributes on this in order to fill all the properties.

Note that when the properties are fetched you do not need to create a new instance of your object.

you can follow this post that references blobs but is concerning your error as well.


An example as you requested would be:

public static void ListContainerMetadataAsync(CloudBlobContainer container)
{
    // Fetch container attributes in order to populate the container's 
       properties and metadata.
     container.FetchAttributes();

    // Enumerate the container's metadata.
    Console.WriteLine("Container metadata:");
    foreach (var metadataItem in container.Metadata)
    {
        Console.WriteLine("\tKey: {0}", metadataItem.Key);
        Console.WriteLine("\tValue: {0}", metadataItem.Value);
    }
}

You can read more at docs.microsoft.

Barr J
  • 10,636
  • 1
  • 28
  • 46
  • great thanks :) can i use below query for getting sub folder last updated file as well ? var latest = fileShare.GetRootDirectoryReference().ListFilesAndDirectories() .OfType() .OrderByDescending(m => m.Properties.LastModified) .ToList() .First(); I have separate question you can help i guess pls help me _ https://stackoverflow.com/questions/52035111/how-do-we-track-azure-file-storage-folder-is-updated-or-not – Neo Aug 27 '18 at 10:23
  • 1
    Yes, I believe you can and I'll do my best to assist :) – Barr J Aug 27 '18 at 10:24
  • thanks a lot ohh i just noticed that , i have uploaded one new file just now into that folder but still LastModified is old date , it means LastModified is separate for that folder and file :O what to do now ? – Neo Aug 27 '18 at 10:36
  • I want to check whether any new file is updated into any sub-fodler of main folder or not within 24hr. – Neo Aug 27 '18 at 10:37
  • can we use any linq query like i mentioned into question ? – Neo Aug 27 '18 at 10:39
  • I tried linq query i posted in question but getting error - Sequence contains no elements' – Neo Aug 27 '18 at 10:53