How to Detect if OneDrive is Syncing Files?

When files are transferred to a directory that Onedrive has been set to be in sync with, the files get pushed to Onedrive either immediately or after a few seconds.

When a robot’s final step involves pushing a file to that particular directory, the sync remains incomplete since the robot directly terminates the session as it has reached the end of what is was programmed to perform.

I’d like to know if its possible to apply a condition where the robot keeps the session active as long as the sync takes place. Right now we are using parameterized delays but sometimes the files can be 40-50MB and a delay is not exactly the best approach as that would involve the use of massive delays.

Unfortunately the client cannot provide API details due to their company policies so we have to look for an alternative like maybe a custom VB.Net or C# code that could check if OneDrive is syncing files.

Help would be most appreciated, thanks in advance.

@Yoichi @ppr

Kind Regards,
Ashwin A.K

How about using UiPath O365 activities to upload the file(s) straight to OneDrive?

some parts are unclear, but we faced the same:

  • in some environments one drive sync was not disturbing
  • in others it causes fails

How about an analysis of the file handlers (manual analysis round at the beginning)?

Hello @ashwin.ashok

  • Use “Invoke PowerShell Script” activity.
  • Set script to check OneDrive sync status.
  • Capture output in UiPath variable (e.g., powershellOutput).
  • Use an “If” activity to check if powershellOutput.Contains("OneDrive sync is complete").
  • In the “Then” section, proceed with your robot logic; in the “Else” section, add delay or retry logic.

Thanks & Cheers!!!

You can use the Powershell script from the following link: windows - How can I check status of files/folders in OneDrive folder whether it is synced or not using c# or PowerShell? - Stack Overflow

The script modified for the Invoke Powershell activity:

String.Format("$OneDriveDocs = '{0}' 
$Shell = (New-Object -ComObject Shell.Application).NameSpace((Split-Path $OneDriveDocs))
$Status = $Shell.getDetailsOf($Shell.ParseName((Split-Path $OneDriveDocs -Leaf)),303)
echo $Status", in_OneDriveFolderFullPath)

The status is “Sync pending” if OneDrive is still syncing the folder.

Example code to wait as long as the status is “Sync pending”:

WaitForOneDriveSync.xaml (12.8 KB)

You might want to add a timeout check so the robot doesn’t wait forever.

1 Like

Hi @ppr ,

As always, appreciate your response!
This is an interesting approach, I’ll reply back if I find anything useful with this.

Kind Regards,
Ashwin A.K

Hi @ptrobot ,

Appreciate your response and it works!
I wanted something with VB.Net or C# but I guess we can’t achieve it that way.

Kind Regards,
Ashwin A.K

You are welcome. Here’s code in VB.NET that you can use with Invoke Code. It’s slower than the Powershell script since it uses reflection.

InArgument: in_FolderPath
OutArgument: out_Status

Dim shellType = Type.GetTypeFromProgID("Shell.Application")
Dim shell = Activator.CreateInstance(shellType)
Dim folder = shellType.InvokeMember("Namespace", Reflection.BindingFlags.InvokeMethod, Nothing, shell, New Object() {Path.GetDirectoryName(in_FolderPath)})
Dim status = shellType.InvokeMember("GetDetailsOf", Reflection.BindingFlags.InvokeMethod, Nothing, folder, New Object() {shellType.InvokeMember("ParseName", Reflection.BindingFlags.InvokeMethod, Nothing, folder, New Object() {Path.GetFileName(in_FolderPath)}), 303})

out_Status = status.ToString

Appreciate the VB.Net code @ptrobot !

Kind Regards,
Ashwin A.K

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.