UiPath

【UiPath】Example of using MicrosoftOffice365 file-related activities

In UiPath Studio development, there are cases where you want to manipulate files and folders located on OneDrive or SharePointOnline in Office365.

This article describes how to manipulate files and folders located on Office365 using Microsoft Office365 Activities.

 

 Related Articles Learn the Creation Techniques f UiPath robotics creation with Udemy’s online courses that take it up a notch

This site was created by translating a blog created in Japanese into English using the DeepL translation.

Please forgive me if some of the English text is a little strange

How to Prepare and Use Office365 Activities

How to Install Office365 Activities

Microsoft Office365 Activities are not present in the process created by default.

A separate MicrosoftOffice365.Activities activity package must be added.

 

For instructions on how to install Microsoft Office365 Activities, please refer to the Installing the Office365 Activities Package article.

 

How to use Office365 Activities

Each Office365 activity is used by placing the activity within the “Microsoft Office 365 Scope” or “Use OneDrive and SharePoint”.

The “Microsoft Office 365 Scope” is recommended since all activities under the “Integration>Microsoft>Office365” can be used.

However, “App Registration” must be configured for AzureAD.

 

F-pen
F-pen
See Authentication with Microsoft Office 365 Scope for specific setup instructions.

“Use OneDrive and SharePoint” only uses activities under the “Integration>Microsoft>Office365>Files” and can only manipulate files on Office365.

sea other
sea other
See Authentication with OneDrive and SharePoint for specific setup instructions.

 

List of file manipulation activities in Office365

Activities that manipulate Office365 files can be found under “Integration>Microsoft>Office365>Files”.

 

The following table shows the activities under “Integration>Microsoft>Office365>Files”.

Activity Location Activity Name What you can do in Activities
Integrations> Microsoft> Office365>
Files
Use OneDrive & SharePoint Selects an account to use for OneDrive and SharePoint automation. After you add this activity, add the activities that work with files from OneDrive and SharePoint in Use OneDrive & SharePoint.
Copy File/Folder Uses the Microsoft Graph Copy item API to create a copy of a file or folder and add it to the same or a new parent folder (Destination folder).
Share File/Folder Uses the Microsoft Graph Create sharing link and Add permissions APIs to share a file or folder drive item with the specified recipients.
Delete File/Folder Uses the Microsoft Graph Delete item API to delete a specified file or folder in your OneDrive or SharePoint site (DriveItem).
Get File/Folder Uses the Microsoft Graph Get item API to get the metadata of a specified item with a known ID (ItemID).
Move File/Folder Uses the Microsoft Graph Move item API to move a specified file or folder to a new parent folder (Destination folder) with the option to change its name.
Find Files And Folders Uses the Microsoft Graph Search items and Shared files APIs to find the files, metadata, and/or contents that match the values of your search parameters (Query).
Export File as PDF Uses the Microsoft Graph Convert content API to convert a OneDrive or SharePoint file to a PDF and save it to a local location.
Upload File Uses the Microsoft Graph Resumable upload API to upload a local file to your OneDrive or SharePoint account.
Download File Uses the Microsoft Graph Download file API to download a specified file from your OneDrive or SharePoint site to a local location.
Create Folder Uses the Microsoft Graph Create folder API to create a new folder (FolderName) in a specified parent directory (Destination folder).
For Each File/Folder Uses the Microsoft Graph Microsoft Search API to perform an activity or a series of activities on each file/folder that matches the filter criteria.

 

F-pen
F-pen
For other activities, see the list of Office365 activities.

 

Manipulate files and folders on Office365

To manipulate files and folders on OneDrive and SharePointOnline in Office365, use the activity under “Integration>Microsoft>Office365>Files”.

sea other
sea other
In this chapter, I’ll show you some examples of frequently used activities.

 

Find Files And Folders

To work with files and folders located on OneDrive or SharePointOnline, first search for the “Find Files And Folders” activity to obtain the “Microsoft.Graph.DriveItem”.

The retrieved DriveItem can then be used in other activities to copy, delete, etc.

 

Find Files And Folders setting items

設定場所 設定項目 設定内容
Properties Common DisplayName The display name of the activity.
Input Query Defines the free text search phrase for the files or folders to retrieve.
Subfolder (Optional) The path of a subfolder in which to search (e.g. SomeFolder or SomeFolder/Another/OneMore).
Misc Private If selected, the values of variables and arguments are no longer logged at Verbose level.
Output First The first file or folder matching the specified query.
Results All files and folders matching the query returned as an array of DriveItems.
Sharepoint Drive Name The name of the drive within OneDrive or SharePoint searched for the indicated files or folders.
Site Url The URL of the SharePoint site searched for the indicated files or folders.

 

 

 

Sample Process 1
Search for folders in the target list of SharePointOnline and display the retrieved DriveItem in the log message.

・Variables

 

・Properties of Microsoft Office 365 Scope

 

・Properties of Find Files And Folders

 

・Properties of For Each

sea other
sea other
For TypeArgument, I’ll set Microsoft.Graph.DriveItem.

 

・Properties of Log Message drListItem

 

 

・Folder of SPO list to be searched

 

・Execution Result Log

F-pen
F-pen
If you only need the first search result, use the drFirstItem set to “First” in the “Find Files And Folders” output.
sea other
sea other
If there are multiple results, use the drListItem set in the “Results” section of the “Find Files And Folders” output.

 

 

Sample Process 2
Search for the target folder in OneDrive and display the retrieved DriveItem in the log message.

・Variables

 

・Properties of “Microsoft Office 365 Scope”

 

・Properties of “Find Files And Folders”

F-pen
F-pen
When searching for OneDrive files, leave the Sharepoint site URL field blank.

 

・Properties of “For Each”

 

・Properties of “Log Message drListItem”

 

・Folders to search in OneDrive

 

・Execution Result Log

 

 

 

Copy File/Folder

To copy files and folders in OneDrive or SharePointOnline, first search for the files and folders in the “Find Files And Folders” activity and get them as “Microsoft.Graph. The following is a list of the most common ways to use this function.

Next, the acquired DriveItem can be used in “Copy File/Folder” to copy the file.

 

Copy File/Folder setting items

Setup Location Setting items Setting details
Properties Common DisplayName The display name of the activity.
Input Destination folder The directory to which this item is copied as a DriveItem.
File or folder to copy The file or folder to copy as a DriveItem.
New name (optional) The name of this item after it is copied.
Misc Private If selected, the values of variables and arguments are no longer logged at Verbose level.
Output DriveItem Copy The new file or folder as a DriveItem.

 

 

 

sample process
Copy files in SharePointOnline to another folder.

 

・Variables

 

・Properties of “Microsoft Office 365 Scope”

 

・Properties of “Find Files And Folders target file for copy

 

・Properties of “Find Files And Folders destination folder

 

・Properties of “Copy File/Folder”

 

・Files to be copied

 

・Destination folder

 

・Destination folder after workflow execution

F-pen
F-pen
The target files are copied.

 

 

Move File/Folder

To move files and folders in OneDrive or SharePointOnline, first search for the files and folders in the “Find Files And Folders” activity and get them as “Microsoft.Graph. The following is a list of the most common ways to use this function.

The retrieved DriveItem can then be used in “Move File/Folder” to move the file.

 

Move File/Folder setting items

Setup Location Setting items Setting details
Properties Common DisplayName The display name of the activity.
Input Destination folder The directory to which this item is moved as a DriveItem.
File or folder to move  The file or folder to move as a DriveItem.
New name (optional) The name of this item after it is moved.
Misc Private If selected, the values of variables and arguments are no longer logged at Verbose level.
Output Reference as The file or folder and its new location as a DriveItem.

 

 

sample process
Move the target file in OneDrive to another folder and rename it.

 

・Variable

 

・Properties of “Microsoft Office 365 Scope”

 

・Properties of “Find Files And Folders Files to be moved”

 

・Properties of “Find Files And Folders Destination Folder”

 

・Properties of “Move File/Folder”

 

・Files to be copied

 

・Destination folder

 

・Folder of files to be moved after workflow execution

sea other
sea other
The file does not exist in the folder of the file to be copied because the file was moved by the workflow execution.

 

・Destination folder after workflow execution

F-pen
F-pen
Since the workflow execution moved the file, the file has been moved to the destination folder and renamed

 

 

Delete File/Folder

To delete a file or folder in OneDrive or SharePointOnline, first search for the file or folder in the “Find Files And Folders” activity and retrieve it as a “Microsoft.Graph.DriveItem”.

Next, the acquired DriveItem can be used in “Delete File/Folder” to delete the file or folder.

 

Delete File/Folder setting items

Setup Location Setting items Setting details
Properties Common DisplayName The display name of the activity.
Input File or folder to delete The DriveItem of the file or folder to delete.
Misc Private If selected, the values of variables and arguments are no longer logged at Verbose level.

 

 

sample process
Delete the target file on SharePointOnline.

 

・Variable

 

・Properties of “Microsoft Office 365 Scope”

 

・Properties of “Find Files And Folders”

F-pen
F-pen
Subfolders of the input can be specified by “/” to specify a lower level folder.

 

・Properties of “Delete File/Folder”

 

・Folder where the file to be deleted is stored

 

・Folder where files to be deleted after workflow execution are saved

sea other
sea other
Presentation_0712.pptx” has been deleted

 

Create Folder

To create a folder on OneDrive or SharePointOnline, use the “Create Folder” activity.

 

Create Folder

Setup Location Setting items Setting details
Properties Common DisplayName The display name of the activity.
Input Folder name A name for the created folder.
Destination folder The DriveItem of the directory in which this folder is created.
Misc Private If selected, the data used in the activity is not logged by Studio.
Output Reference as The created folder as a DriveItem object.

 

 

sample process
Create a folder directly under OneDrive.

 

 

・variable

 

・Properties of “Microsoft Office 365 Scope”

 

・Properties of “Create Folder”

 

・Directly under OneDrive before workflow execution

・Directly under OneDrive after workflow execution

sea other
sea other
A new folder is created directly under OneDrive for the Office365 authenticated user when the workflow is executed.

 

 

 

Upload File

To upload a file to OneDrive or SharePointOnline, first use the “Find Files And Folders” activity to find the folder where the file will be uploaded and retrieve it as a “Microsoft.Graph.DriveItem”.

The retrieved DriveItem can then be used in Upload File to upload the file.

 

Upload File setting items

Setup Location Setting items Setting details
Properties Common DisplayName The display name of the activity.
Input Conflict Behavior  Indicates the conflict resolution behavior in case a file with the same name already exists.
Destination folder The parent folder to which the file is uploaded as a DriveItem.
File to upload The path to a local file to upload.
Metadata The metadata to associate with the resulted DriveItem (it works only for a DriveItem stored in a SharePoint Document Library).
New name (optional) A new name for the uploaded file.
Misc Private If selected, the values of variables and arguments are no longer logged at Verbose level.
Output Reference as The uploaded file as a DriveItem.

 

 

sample process
Upload files on the designated folder in ShraPoint.

 

・Variable

 

・Properties of “Microsoft Office 365 Scope”

 

・Properties of “Find Files And Folders”

 

・Properties of “Upload File”

 

・SharePoint upload destination folder

 

・Destination folder for SharePoint uploads after workflow execution

sea other
sea other
The file you specified in Upload File has been uploaded.

 

 

Download File

To download a file from OneDrive or SharePointOnline, first search for the file to be downloaded in the “Find Files And Folders” activity and retrieve it as a “Microsoft.Graph.DriveItem”.

Next, the file can be downloaded by using the retrieved DriveItem with “Download File”.

 

Download File setting items

Setup Location Setting items Setting details
Properties Common DisplayName The display name of the activity.
Input File to download The DriveItem of the file to download.
Download as file The local path to which the file is downloaded. If left blank, the project directory is used.
Misc Private If selected, the values of variables and arguments are no longer logged at Verbose level.

 

 

sample process
Download the specified file on SharePoint.

 

 

・Variable

 

・Properties of “Microsoft Office 365 Scope”

 

・Properties of “Find Files And Folders”

 

・Properties of “Download File”

 

・Files to be downloaded

 

・Destination folder for download after workflow execution

F-pen
F-pen
The file is downloaded to the specified folder.

 

 

summary

  • To manipulate files and folders on Office365 SharePoint and OneDrive, first install the MicrosoftOffice365.Activities activity package.
  • Place “Microsoft Office 365 Scope” or “Use OneDrive and SharePoint” in the workflow for manipulating Office365 files and place “Integration>Microsoft>Office365>Files” in it.
  • Find Files And Folders” activity to search for target files and folders, and use the results obtained as “Microsoft.Graph.DriveItem” type in other activities to manipulate files and folders.

Back to Table of Contents

 

 Related Articles Learn the Creation Techniques f UiPath robotics creation with Udemy’s online courses that take it up a notch

 same category UiPath

 

The operator of this blog, F-penIT blog