Here is my code I'm using initialized data service client to get the storage blob containers folders and files.

enter image description here

However, while iterating through paginated responses I'm not getting data in a sorted format. I want all the folders/directories to appear on the first pages and then files at the end.

enter image description here

It would be helpful if someone has an idea of how this can be done.

Thanks in advance.

1

There are 1 best solutions below

1
On

Fetching Files and folders from Blob Storage in Pagination

  1. Create a storage account enter image description here

  2. Create a file share account enter image description here

  3. Create a directory / folder in fileshare enter image description here

  4. Use the Connection string of the storage account, fileshare name and folder name in the below code

         string connectionString = "Connection-String";
         CloudStorageAccount cloud_StorageAccount = CloudStorageAccount.Parse(connectionString);
         CloudFileClient cloud_FileClient = cloud_StorageAccount.CreateCloudFileClient();
         CloudFileShare cloud_FileShare = cloud_FileClient.GetShareReference("FileShare");
         CloudFileDirectory root_Directory = cloud_FileShare.GetRootDirectoryReference();
         CloudFileDirectory file_Directory = root_Directory.GetDirectoryReference("Directory_Name");
         List<IListFileItem> files = Get_Files_Directory(file_Directory);
         int i = 0;
         foreach (var item in files)
         {
    
             SampleData s = new SampleData();
             s.ID = i+1;
             s.FileName = ((Microsoft.Azure.Storage.File.CloudFile)item).Name;
             s.FolderName = ((Microsoft.Azure.Storage.File.CloudFile)item).SnapshotQualifiedUri.LocalPath;
    
             _sampleDataList.Add(s);
    
         }``
    

Code Execution enter image description here

The below is the list of sorted files in the pagination Page1 enter image description here

Page2 enter image description here