Determine whether a given path is a sync folder / cloud folder

Peter Bons 20 Reputation points
2023-03-14T13:38:51.3833333+00:00

I have some difficulties to determine whether a given path is a sync folder. With that I mean whether the path is synced by a service like One Drive, Google Drive, DropBox etc.

I've tried it using the StorageFolder like this:

var folder = await StorageFolder.GetFolderFromPathAsync(args[0]);
var info = StorageProviderSyncRootManager.GetSyncRootInformationForFolder(folder);

folder = info.Path as StorageFolder;

var props = await folder?.Properties.RetrievePropertiesAsync(new[]
{
    "System.FolderNameDisplay",
    "System.StorageProviderFileRemoteUri",
    "System.StorageProviderId"
});
foreach (var prop in props)
    Console.WriteLine($"{prop.Key}: {prop.Value}");

but this seems to target One Drive only, not Google Drive for example. Also, it shows results on my windows 11 machine but not on that of a collegue.

Are there any other options I am not aware of?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,650 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
981 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,650 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Osjaetor 475 Reputation points
    2023-06-06T18:33:26.19+00:00

    Hi Peter Bons,

    The best way to determine if a folder is synchronized with services such as OneDrive, Drive or Dropbox, is to use the API or SDK that they provide.

    For OneDrive: You can use the Microsoft Graph API to retrieve the folder metadata and check if the remoteItem property includes fileSystemInfo with the lastModifiedBy property representing OneDrive.

    For Google drive: you can use the Google Drive API. Perform a Files: list request to retrieve the folder metadata. Check if the ownedByMe field is true, which indicates that the folder is synchronized with Google Drive.

    For Dropbox: you must use the Dropbox API. Make a files/get_metadata request to retrieve the folder's metadata. Check if the sharing_info field is present, indicating that the folder is synchronized with Dropbox.

    Regards,

    0 comments No comments