Upload files to Sharepoint

Hi,

I need to upload files to Sharepoint. The library UiPath.MicrosoftOffice365.Activities has the command Upload File. But it only uploads 1 file.
I want to upload 100 files. If I use the loop with Upload File function, it takes a long time and sometimes the call fails.

Is there any function that can upload multiple files to Sharepoint?

Thanks in advance.

1 Like

You can write a macro to upload multiple files to Sharepoint and then invoke the macro in UiPath.

Do you have an example? What language do you use for this macro?

We use VBA. I will share an example with you.

Here is the macro.

sub process()

Dim sourceLocation, Sharepointlocation ,strFileName as string
Dim workbookpath as variant
Dim extractedworkbookpath as string
Dim rng as Range

*Define the source location where all your files are available
sourceLocation=xyz

*Define sharepointlocation where you need to upload your files.
Sharepointlocation=xyz

If you have some specific types of files to be upload to Sharepoint then use the file extension
strFileName=Dir(sourceLocation,"
.xls")

Do while strFileName<>“”
set extractedworkbookpath=workbooks.open(sourcelocation & strFileName, ,True)
extractedworkbookpath.activate
On Error Resume Next
extractedworkbookpath.Saveas Filename:=Sharepointlocation & strFileName, Fileformat:=xlExcel8,createBackup:=False)
If err.Number<>0
extractedworkbookpath.Saveas Filename:=Sharepointlocation & strFileName, Fileformat:=xlExcel8,createBackup:=False)
end if
extractedworkbookpath.close

On Error Goto 0
strFileName=dir()
Loop
LastLine:

end sub

try this one & let me know it it works fine for you.

Thanks for sharing the code! If I understand correctly, your Sharepointlocation is locally on the machine where the macro is running. The macro doesn’t make API calls to Sharepoint and if your machine doesn’t have sync with Sharepoint folder, it won’t work.
I’m having trouble with synchronization, that’s why I’m looking for an API solution. But I assume Sharepoint API does not offer bulk upload…