Why does the UiPath Download File activity fail with "Folders cannot be downloaded with this activity" when using For Each File or Folder?
Issue Description
Product Details
- UiPath Studio/Robot Version: >=24.10.x
- Package: UiPath.MicrosoftOffice365.Activities
Overview
When using the Download File activity in combination with the For Each File or Folder activity, you may encounter an exception indicating that folders cannot be downloaded.
This occurs when the workflow attempts to pass a folder-type DriveItem to the Download File activity, which only supports files.
Scenario / Steps to Reproduce
1. Use the For Each File or Folder activity
- Set What to return = Files and folders or Folders
2. Inside the loop, use the Download File activity
- Set File to download = CurrentItem
3. Run the workflow
Error
25.10.11+Branch.support-v25.10.Sha.e6a0d3c45f5a18ef024a718b6660e02b739cb876.e6a0d3c45f5a18ef024a718b6660e02b739cb876Source: Download File
Message: Error retrieving file. Please revise 'Download File' activity from where the file FOLDER_NAME originated. Folders cannot be downloaded with this activity. Please input a different DriveItem.
Exception Type: UiPath.MicrosoftOffice365.Office365Exception
in Main.xaml
at DownloadFileConnections "Download File"
at Sequence "Then"
at If "If"
at Sequence "Do"
at ForEachFileFolderConnections "For Each File or Folder"
at Sequence "Main Sequence"
at Main "Main"
UiPath.MicrosoftOffice365.Office365Exception: Error retrieving file. Please revise 'Download File' activity from where the file FOLDER_NAME originated. Folders cannot be downloaded with this activity. Please input a different DriveItem.
—> UiPath.MicrosoftOffice365.Office365InternalException: Error retrieving file. Please revise 'Download File' activity from where the file FOLDER_NAME originated. Folders cannot be downloaded with this activity. Please input a different DriveItem.
—> System.InvalidOperationException: Error retrieving file. Please revise 'Download File' activity from where the file FOLDER_NAME originated. Folders cannot be downloaded with this activity. Please input a different DriveItem.
—> UiPath.MicrosoftOffice365.Office365Exception: Folders cannot be downloaded with this activity. Please input a different DriveItem.
at UiPath.MicrosoftOffice365.Services.GraphServiceClientProxy.DownloadFileAsync(DownloadFileRequest request, CancellationToken cancellationToken)
at UiPath.MicrosoftOffice365.Files.Models.O365DriveLocalItem.ResolveAsync(Boolean force, CancellationToken ct)
— End of inner exception stack trace —
at UiPath.MicrosoftOffice365.Files.Models.O365DriveLocalItem.ResolveAsync(Boolean force, CancellationToken ct)
at UiPath.MicrosoftOffice365.Activities.Files.DownloadFileConnections.SafeExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
at UiPath.MicrosoftOffice365.Activities.BaseLeafConnectionServiceActivityWithoutBindings.ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
— End of inner exception stack trace —
at UiPath.MicrosoftOffice365.Services.GraphServiceClientProxy.DownloadFileAsync(DownloadFileRequest request, CancellationToken cancellationToken)
at UiPath.MicrosoftOffice365.Files.Models.O365DriveLocalItem.ResolveAsync(Boolean force, CancellationToken ct)
— End of inner exception stack trace —
at UiPath.MicrosoftOffice365.Activities.BaseLeafConnectionServiceActivityWithoutBindings.ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
at UiPath.Shared.Activities.AsyncTaskCodeActivityImplementation.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at UiPath.Shared.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at UiPath.Shared.Activities.ContinuableAsyncCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at UiPath.MicrosoftOffice365.Activities.Office365BaseClientActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
Cause
This behavior is expected by design.
The Download File activity only supports downloading DriveItem objects of type File. When a folder is passed, the activity throws an exception because folders are not downloadable entities in Microsoft Graph via this activity.
Resolution
Approach #1: Retrieve Only Files
In case only files are needed:
1. In For Each File or Folder
- Set What to return = Files
2. Keep
Download File → File to download = CurrentItem
This ensures only file-type DriveItems are processed.
Approach #2: Add Conditional Filtering (Recommended for mixed content)
If the source contains both files and folders:
1. Keep For Each File or Folder activity with the original configuration
- What to return = Files and folders (or Folders)
2. Add an If activity inside the loop:
Not CurrentItem.IsFolder
Inside the Then branch:
Download File → File to download = CurrentItem
This ensures:
- Only files are downloaded
- Folders are safely skipped
- No runtime exception occurs
Best Practices
- Always validate the type of DriveItem before performing file operations
- Use CurrentItem.IsFolder to prevent invalid operations
- Prefer filtering at the source whenever possible to improve performance
References


