Reputation: 63
I am creating a webjob app to periodically (scheduled) read an azure file share and process files. I am using the C# ApI examples provided but cannot figure out how to get file metadata with my directory listing. I would like to do something as simple as sort files by modified date. Does anyone have an example of fetching metadata with the Listing Files.
FileResultSegment resultSegment = await share.GetRootDirectoryReference().ListFilesAndDirectoriesSegmentedAsync(token);
results.AddRange(resultSegment.Results);
Results in no MetaData or Properties defined for the IListFileItem below.
foreach (IListFileItem listItem in results)
{
// listItem type will be CloudFile or CloudFileDirectory
Console.WriteLine("- {0} (type: {1})", listItem.Uri, listItem.GetType());
}
Upvotes: 1
Views: 1635
Reputation: 63
Building on Thomas's post... This is the only way I have found.
foreach (var item in results)
{
if (item is CloudFile)
{
var cloudFile = (CloudFile) item;
cloudFile.FetchAttributes();
// You can now access metadata and properties
//cloudFile.Metadata
//cloudFile.Properties
}
else if (item is CloudFileDirectory)
{
var cloudFileDirectory = (CloudFileDirectory)item;
// You can now access metadata and properties
//cloudFileDirectory.Metadata
//cloudFileDirectory.Properties
}
}
Upvotes: 1
Reputation: 29746
What about casting your results ?
foreach (var item in results)
{
if (item is CloudFile)
{
var cloudFile = (CloudFile) item;
// You can now access metadata and properties
//cloudFile.Metadata
//cloudFile.Properties
}
else if (item is CloudFileDirectory)
{
var cloudFileDirectory = (CloudFileDirectory)item;
// You can now access metadata and properties
//cloudFileDirectory.Metadata
//cloudFileDirectory.Properties
}
}
Upvotes: 1