0

我已将文件上传到 Azure 文件服务帐户上的文件夹。现在我想列出这些文件。当代码到达这一行时

FileResultSegment resultSegment = await dir.ListFilesAndDirectoriesSegmentedAsync(token);

它关闭。没有抛出错误,所以我无法弄清楚问题所在。完整的方法如下。有没有人让这个工作?

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();
}
4

0 回答 0