How to Change the Saved Location for Files Downloaded Using "Download File" Activity from UiPath.MicrosoftOffice365.Activities

Download File activity from UiPath.MicrosoftOffice365.Activities - Where the downloaded file is saved and how to change its saved location?

Issue Description

While trying to use the Download File activity from UiPath.MicrosoftOffice365.Activities package for a OneDrive file is not clear where the file is saved and how to store/save it to a desired location.

Root Cause

At this moment, the file is saved temporarily by default in the robot's local temp location (%temp%).

There is no text output in the activity to provide the local location of the file to be stored.

image.png

Resolution

Note: In this guide, these prerequisites were used:

  • Studio/Robot 23.10.8
  • UiPath.MicrosoftOffice365.Activities.2.6.25 and UiPath.System.Activities.23.10.6 from https://pkgs.dev.azure.com/uipath/Public.Feeds/_packaging/UiPath-Official/nuget/v3/index.json external feed
  • At least a file in OneDrive and a valid connection to OneDrive in the Integration Service

To overcome this limitation, you will need to perform these steps in your Studio project:

  1. Install UiPath.MicrosoftOffice365.Activities.2.6.25 from https://pkgs.dev.azure.com/uipath/Public.Feeds/_packaging/UiPath-Official/nuget/v3/index.json external feed.
  2. In the Download File (UiPath.MicrosoftOffice365.Activities.Files.DownloadFileConnections) activity, select the file to download and create an output variable for it (for example out_File):

  1. Two approaches can be used at this point.

Approach #1 - Using a Copy File activity from the UiPath.System.Activities package

Add a Copy File activity and configure it as in the below example. Adjust the From and To based on your automation requirements.

From set to out_File.LocalPath
To set to "C:\Users\REPLACE_WITH_YOUR_USERNAME\Downloads\"+out_File.FullName

image.png

Approach #2 - Using an Invoke activity for CSharp from the UiPath.System.Activities package

Add a Multiple Assign activity and in it create two System.String variables.

localTempFilePath with value out_File.LocalPath

FileNameToUse with value out_File.FullName

image.png

  1. Add an Invoke Code activity for CSharp
  • Add these System.String arguments localTempFilePath and FileNameToUse as in the below screenshot:

  • In the Imports panel add the System.IO reference

  • In the Edit Code add this code. Adapt the destinationFile location with your desired one where the robot has Full Control (or at least View, Write, and Execute) permission.
  • string sourceFile = localTempFilePath; //using argument for source file string destinationFile = @"C:\Users\REPLACE_WITH_YOUR_USERNAME\Downloads\" + FileNameToUse; //using argument for destination file // Ensure that the target does not exist. if (File.Exists(destinationFile)) File.Delete(destinationFile); // Copy the file. File.Copy(sourceFile, destinationFile);


Example:

image.png


After executing the automation (for both Approaches), the file will be saved in your provided location.

Example:

1 Like