Discuss this help topic in SecureBlackbox Forum

Clouds: Get directory structure and file list

The first step is to get the root folder of the account. Call the TElOneDriveDataStorage.AcquireObject() method without parameters and cast the returned object to TElOneDriveFolder type. Use the object's methods to perform operations with files and folders located in the root directory of OneDrive service. When the object is not needed anymore, call its Release() method.

C#:


TElOneDriveFolder root = storage.AcquireFolder() as TElOneDriveDataStorage;
Console.WriteLine("Root folder: {0} (children = {1}, size = {2})",
                  root.Name, root.Count, root.Size);
root.Release();

Once you have a folder object, you can use its methods to list the folders and files contained in this folder using TElOneDriveFolder.List() method. This method accepts an instance of the TElDataStorageObjectList class, which is filled in the methods with different types of objects, which match the type of the object on the server. For folders there are TElOneDriveFolder and TElOneDriveAlbum (a special kind of folder, a descendant of TElOneDriveFolder) available. For files there are more variants there - TElOneDriveFile for "generic" files, and TElOneDriveAudio, TElOneDriveNotebook, TElOneDrivePhoto and TElOneDriveVideo for specific object types on the server.

C#:


TElDataStorageObjectList list = new TElDataStorageObjectList();
root.List(list);

Console.WriteLine("Listed {0} objects:", list.Count);
for (int i = 0; i < list.Count; i++)
{
    TElOneDriveDataStorageObject obj = list.get_Objects(i) as
                                       TElOneDriveDataStorageObject;
    Console.WriteLine(" - {0} ({1}, size = {2})",
                      obj.Name, obj.ObjectType, obj.Size);
}

list.Dispose();

Also you can retrieve the list of just child folders (and albums) of the given folder. Do this with TElOneDriveFolder.ListFolders() method. This method returns only TElOneDriveFolder and TElOneDriveAlbum objects.

C#:


TElDataStorageObjectList list = new TElDataStorageObjectList();
root.ListFolders(list);

Console.WriteLine("Listed {0} folders:", list.Count);
for (int i = 0; i < list.Count; i++)
{
    TElOneDriveDataStorageObject obj = list.get_Objects(i) as
                                       TElOneDriveDataStorageObject;
    Console.WriteLine(" - {0} ({1}, size = {2})",
                      obj.Name, obj.ObjectType, obj.Size);
}

list.Dispose();

Please note that the list is not cleared by the above List*() methods, and new objects are appended to the list.

When the list is destroyed/disposed, it also destroys/disposes the contained objects. So, if you need a folder or a file object to use them after the list destroyed/disposed, you need to clone the object and use the copy.

Also, it is possible to store not objects but their IDs. When you need to perform any operation with a file or a folder with a known ID, it is very easy to get its object by calling TElOneDriveDataStorage.AcquireObject() method and passing the ID to it.

Virtual Folders

Besides regular folders OneDrive introduces so-called Virtual Folders:

  • Recent Docs - the list of files, that were recently accessed. Contents of this folder can be enumerated using TElOneDriveDataStorage.ListRecent() method.
  • Shared Objects - the list of objects, which were shared with the current user. Contents of this folder can be enumerated using TElOneDriveDataStorage.ListShared() method.
  • Friendly Folders - the real folders, which have "friendly names". You can access them using their fixed name and calling TElOneDriveDataStorage.ListFriendly() method. There are several such folders known: my_documents, public_documents, my_photos, camera_roll.
  • Recycle Bin - the trash can for deleted files and objects. This folder is not accessible with current version of SecureBlackbox.

How To articles about OneDrive cloud

Discuss this help topic in SecureBlackbox Forum