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.

1 Answer 1

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.

6
  • great thanks :) can i use below query for getting sub folder last updated file as well ? var latest = fileShare.GetRootDirectoryReference().ListFilesAndDirectories() .OfType<CloudFileShare>() .OrderByDescending(m => m.Properties.LastModified) .ToList() .First(); I have separate question you can help i guess pls help me _ stackoverflow.com/questions/52035111/…
    – Neo
    Commented Aug 27, 2018 at 10:23
  • 1
    Yes, I believe you can and I'll do my best to assist :)
    – Barr J
    Commented Aug 27, 2018 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
    Commented Aug 27, 2018 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
    Commented Aug 27, 2018 at 10:37
  • can we use any linq query like i mentioned into question ?
    – Neo
    Commented Aug 27, 2018 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.