none
CloudFileDirectory dir = new CloudFileDirectory(uri) errors on ListFilesAndDirectoriesSegmentedAsync() RRS feed

  • Question

  • public async Task<IActionResult> OpenFolder(string folderUri)
            {
                Uri uri = new Uri(folderUri);
    
                CloudFileDirectory dir = new CloudFileDirectory(uri);
                var directoryContents = await GetAllFilesFromDirectory(dir);
    
                var vm = new DirectoryViewModel
                {
                    Directory = dir,
                    Items = directoryContents
                };
    
                return RedirectToAction("Index", vm);
            }
    
    
            private async Task<List<IListFileItem>> GetAllFilesFromDirectory(CloudFileDirectory directory)
            {
                List<IListFileItem> results = new List<IListFileItem>();
                FileContinuationToken token = null;
                do
                {
                    FileResultSegment resultSegment = await directory.ListFilesAndDirectoriesSegmentedAsync(token);
                    results.AddRange(resultSegment.Results);
                    token = resultSegment.ContinuationToken;
                }
                while (token != null);
    
                return results;
            }

    The above is my code.  The error seems a little off:

    StorageException: The specified resource does not exist.

    Because the Uri I'm using is from an existing CloudFileDirectory item's Uri property.

    Debug on the directory shows no nulls in e.g. share and file client.

    Am I approaching this in the right way?  What I'm actually implementing is 'click on the folder in the UI, get to see what is in the folder'.

     
    Friday, August 30, 2019 3:06 PM

All replies

  • Have you gotten a change to review the following post in SO: https://stackoverflow.com/questions/31340209/azurestorage-cloudfiledirectory-listfilesanddirectories-worthless

    The first answer used a code snippet to list the content of directories, not sure if it will help with the UI approach but it's worth taking a look at:

    CloudFileDirectory rootDir = myShare.GetRootDirectoryReference();
    // Get directory items once
    IEnumerable<IListFileItem> azureItems = rootDir.ListFilesAndDirectories();
    CloudFileDirectory azureDirectories = azureItems.OfType<CloudFileDirectory>();
    CloudFile azureFiles = azureItems.OfType<CloudFile>();

     
    Friday, August 30, 2019 6:31 PM
    Moderator
  • @AnotherTonyWatts Is there any update on the issue?

    If the suggested answer helped for your issue, do click on "Mark as Answer" and “Vote as Helpful” on the post that helps you, this can be beneficial to other community members.

    Wednesday, September 4, 2019 5:19 AM
    Moderator
  • @AnotherTonyWatts Is there any update on the issue?

    If the suggested answer helped for your issue, do click on "Mark as Answer" and “Vote as Helpful” on the post that helps you, this can be beneficial to other community members.

    Monday, September 9, 2019 5:20 AM
    Moderator