I have uploaded files to a folder on my Azure file service account. Now I would like to list those files. When the code reaches this line
FileResultSegment resultSegment = await dir.ListFilesAndDirectoriesSegmentedAsync(token);
It closes. No error is thrown, so I cannot figure out the issue. The full method is below. Has anyone got this to work?
public async void ListFiles()
{
const string clientShare = "clientshare";
const string profileDirectory = "profiledirectory";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
CloudFileShare share = fileClient.GetShareReference(clientShare);
CloudFileDirectory root = share.GetRootDirectoryReference();
CloudFileDirectory dir = root.GetDirectoryReference(profileDirectory);
if (share.Exists())
{
Console.WriteLine("Share Exists");
}
if (dir.Exists())
{
Console.WriteLine("Profiledirectory Exists");
}
Console.WriteLine("List Files/Directories in root directory");
var results = new List<IListFileItem>();
FileContinuationToken token = null;
try
{
do
{
FileResultSegment resultSegment = await dir.ListFilesAndDirectoriesSegmentedAsync(token);
results.AddRange(resultSegment.Results);
token = resultSegment.ContinuationToken;
}
while (token != null);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
// Print all files/directories listed above
foreach (IListFileItem listItem in results)
{
// listItem type will be CloudFile or CloudFileDirectory
Console.WriteLine("- {0} (type: {1})", listItem.Uri, listItem.GetType());
}
Console.ReadKey();
}