activities
latest
false
Productivity Activities
Last updated Oct 23, 2024

Google Drive APIs

Creates a Google Drive service.

Namespace: UiPath.Gsuite.Activities.API

Assembly: UiPath.Gsuite.Activities.API (in UiPath.Gsuite.Activities.API.dll)

Constructors

ConstructorDescriptionSyntax
GoogleDriveServiceInitializes a new instance of the GoogleDriveService class
public class GoogleDriveService : IGoogleDriveServicepublic class GoogleDriveService : IGoogleDriveService

Methods

NameDescription
ApplyFileLabelsApplies Google Drive labels to the specified file.
ClearFileLabelFieldsRemoves one or multiple label fields from a file.
CopyFileCopies a file on a specified Google Drive location.
CreateFolderCreates a folder in the specified Google Drive location.
DeleteItemDeletes a specified file or folder.
DownloadFileDownloads the specified file.
GetDriveLabelsGets Drive labels with empty fields.
GetFileGets a file from Google Drive by relative path or by URL, ID or full path.
GetFileLabelsRetrieves a list of files from the specified Google Drive location.
GetFilesRetrieves a list of files from the specified Google Drive location.
GetFilesandFoldersRetrieves a list of files and folders from the specified Google Drive location.
GetFolder

Gets a folder from Google Drive by relative path, or by URL, ID or full path.

GetFoldersRetrieves a list of folders from the specified Google Drive location.
GetItem

Gets a file or folder from Google Drive by relative path or by URL, ID or full path.

MoveFileMoves a folder to the specified destination folder in Google Drive.
MoveFolderMoves a folder to the specified destination folder in Google Drive.
RefreshFileGets the latest version of the specified file.
RefreshFolderGets the latest version of the specified folder.
RefreshItemGets the latest version of the specified file or folder.
RemoveFileLabelsRemoves labels from a file.
ShareFile

Shares a file with anyone, with a domain, or with the specified recipients.

ShareFolder

Shares a folder with anyone, with a domain, or with the specified recipients.

UploadFileUploads a file to Google Drive
UploadFilesUploads files to Google Drive

Example

In the following example, you can see how you can use the APIs to rename all files from a Google Drive folder by adding a subfix.
using GoogleWorkspaceCodedWorkflows.ObjectRepository;
using System;
using System.Collections.Generic;
using System.Data;
using UiPath.CodedWorkflows;
using UiPath.Core;
using UiPath.Core.Activities.Storage;
using UiPath.Excel;
using UiPath.Excel.Activities;
using UiPath.Excel.Activities.API;
using UiPath.Excel.Activities.API.Models;
using UiPath.GSuite.Activities.Api;
using UiPath.Mail.Activities.Api;
using UiPath.Orchestrator.Client.Models;
using UiPath.Testing;
using UiPath.Testing.Activities.TestData;
using UiPath.Testing.Activities.TestDataQueues.Enums;
using UiPath.Testing.Enums;
using UiPath.UIAutomationNext.API.Contracts;
using UiPath.UIAutomationNext.API.Models;
using UiPath.UIAutomationNext.Enums;

namespace GoogleWorkspaceCodedWorkflows
{
    public class Rename_all_the_files_in_a_Google_Drive_folder : CodedWorkflow
    {
        [Workflow]
        public void Execute(string NameSubfix)
        {
           var service = google.Drive(connections.Drive.<connectionID>);
            
            var folderUrl ="https://drive.google.com/drive/folders/1sE7UqjderUPv24Rxkto5jyefAuVLeVCz";
            var folder = service.GetFolder(folderUrl,IdentificationType.UrlOrId);
            var files = service.GetFiles(folder);
            foreach (var file in files)
            {
                System.Console.WriteLine(file.FullName);
                file.Move(folder,file.FullName+"-"+NameSubfix,ConflictBehavior.Replace);
                
            }
        }
    }
}using GoogleWorkspaceCodedWorkflows.ObjectRepository;
using System;
using System.Collections.Generic;
using System.Data;
using UiPath.CodedWorkflows;
using UiPath.Core;
using UiPath.Core.Activities.Storage;
using UiPath.Excel;
using UiPath.Excel.Activities;
using UiPath.Excel.Activities.API;
using UiPath.Excel.Activities.API.Models;
using UiPath.GSuite.Activities.Api;
using UiPath.Mail.Activities.Api;
using UiPath.Orchestrator.Client.Models;
using UiPath.Testing;
using UiPath.Testing.Activities.TestData;
using UiPath.Testing.Activities.TestDataQueues.Enums;
using UiPath.Testing.Enums;
using UiPath.UIAutomationNext.API.Contracts;
using UiPath.UIAutomationNext.API.Models;
using UiPath.UIAutomationNext.Enums;

namespace GoogleWorkspaceCodedWorkflows
{
    public class Rename_all_the_files_in_a_Google_Drive_folder : CodedWorkflow
    {
        [Workflow]
        public void Execute(string NameSubfix)
        {
           var service = google.Drive(connections.Drive.<connectionID>);
            
            var folderUrl ="https://drive.google.com/drive/folders/1sE7UqjderUPv24Rxkto5jyefAuVLeVCz";
            var folder = service.GetFolder(folderUrl,IdentificationType.UrlOrId);
            var files = service.GetFiles(folder);
            foreach (var file in files)
            {
                System.Console.WriteLine(file.FullName);
                file.Move(folder,file.FullName+"-"+NameSubfix,ConflictBehavior.Replace);
                
            }
        }
    }
}
In the following example, you can see how you can use the APIs to read all files from a folder including the subfolders.
using GoogleWorkspaceCodedWorkflows.ObjectRepository;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using UiPath.CodedWorkflows;
using UiPath.Core;
using UiPath.Core.Activities.Storage;
using UiPath.Excel;
using UiPath.Excel.Activities;
using UiPath.Excel.Activities.API;
using UiPath.Excel.Activities.API.Models;
using UiPath.GSuite.Activities.Api;
using UiPath.GSuite.Drive.Models;
using UiPath.Mail.Activities.Api;
using UiPath.Orchestrator.Client.Models;
using UiPath.Testing;
using UiPath.Testing.Activities.TestData;
using UiPath.Testing.Activities.TestDataQueues.Enums;
using UiPath.Testing.Enums;
using UiPath.UIAutomationNext.API.Contracts;
using UiPath.UIAutomationNext.API.Models;
using UiPath.UIAutomationNext.Enums;

namespace GoogleWorkspaceCodedWorkflows
{
    public class ReadAllFilesFromAFolder : CodedWorkflow
    {
        [Workflow]
        public void Execute()
        {            
            var service = google.Drive(connections.Drive.<connectionID>);     
         
            // Read All files from Google Drive and its subfolders 
            readFilesInAFolder(null,service);
            
        }
        // Read All files from a Folder including all subfolders
        public void readFilesInAFolder(IFolder? googleFolder, IGoogleDriveService service)
        {
            var filesAndFolders = service.GetFilesAndFolders(googleFolder);
        
            foreach (var fileFolder in filesAndFolders.OrderBy(f=> f.IsFolder))
            {
                if(!fileFolder.IsFolder)
                {
                    var folder = service.GetFolder(fileFolder.Item.ParentId);
                    
                    Log("Folder: "+ folder.FullName+" FileName: "+fileFolder.FullName+ " Type: "+fileFolder.Item.MimeType);
                }
                else
                {
                    readFilesInAFolder(fileFolder as IFolder, service);
                }
            }
            
        }
    }
    
}using GoogleWorkspaceCodedWorkflows.ObjectRepository;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using UiPath.CodedWorkflows;
using UiPath.Core;
using UiPath.Core.Activities.Storage;
using UiPath.Excel;
using UiPath.Excel.Activities;
using UiPath.Excel.Activities.API;
using UiPath.Excel.Activities.API.Models;
using UiPath.GSuite.Activities.Api;
using UiPath.GSuite.Drive.Models;
using UiPath.Mail.Activities.Api;
using UiPath.Orchestrator.Client.Models;
using UiPath.Testing;
using UiPath.Testing.Activities.TestData;
using UiPath.Testing.Activities.TestDataQueues.Enums;
using UiPath.Testing.Enums;
using UiPath.UIAutomationNext.API.Contracts;
using UiPath.UIAutomationNext.API.Models;
using UiPath.UIAutomationNext.Enums;

namespace GoogleWorkspaceCodedWorkflows
{
    public class ReadAllFilesFromAFolder : CodedWorkflow
    {
        [Workflow]
        public void Execute()
        {            
            var service = google.Drive(connections.Drive.<connectionID>);     
         
            // Read All files from Google Drive and its subfolders 
            readFilesInAFolder(null,service);
            
        }
        // Read All files from a Folder including all subfolders
        public void readFilesInAFolder(IFolder? googleFolder, IGoogleDriveService service)
        {
            var filesAndFolders = service.GetFilesAndFolders(googleFolder);
        
            foreach (var fileFolder in filesAndFolders.OrderBy(f=> f.IsFolder))
            {
                if(!fileFolder.IsFolder)
                {
                    var folder = service.GetFolder(fileFolder.Item.ParentId);
                    
                    Log("Folder: "+ folder.FullName+" FileName: "+fileFolder.FullName+ " Type: "+fileFolder.Item.MimeType);
                }
                else
                {
                    readFilesInAFolder(fileFolder as IFolder, service);
                }
            }
            
        }
    }
    
}
  • Constructors
  • Methods
  • Example

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.