4
votes

I am trying to upload a file from R to SharePoint. I have found similar questions like Saving files to SharePoint folder from R, Saving a file to Sharepoint with R and Copying file to sharepoint library in R but I haven't been able to get it working for myself.

The things I tried so far:

system("curl --ntlm --user username:password --upload-file file.xslx https://companyname.sharepoint.com/sites/sitename/Shared%20documents/file.xlsx")

system("curl --ntlm --user username:password --upload-file file.xslx https://companyname.sharepoint.com/sites/sitename/Documents/file.xlsx")

system("curl --ntlm --user username:password --upload-file file.xslx https://companyname.sharepoint.com/sites/sitename/Shared documents/file.xlsx")

system("curl --ntlm --user username:password --upload-file file.xslx \\\\companyname.sharepoint.com@SSL\\sites\\sitename\\Shared%20documents\\file.xlsx")

Note that our SharePoint is in our native language (Dutch), so the folder "Shared documents" is "Gedeelde documenten". I tried both languages but without success. Not sure if I am supposed to the English names or the Dutch ones.

My guess is that the url I use is not in the correct format or such, so I have played around with that but can't come up with the correct way myself. Any help is much appreciated.

EDIT:

This is how the page and folder in Sharepoint looks like. Full url (guessed the part from /Forms till the end is not needed in the command): https://companyname.sharepoint.com/sites/SiteName/Gedeelde%20documenten/Forms/AllItems.aspx?id=%2Fsites%2FOfficeSFMT%2FGedeelde%20documenten%2FGeneral%2FTest

Screenshot of the folder: foldernames

My best guess was trying: "--upload-file C:/Users/UserName/Documents/Test.txt", "companyname.sharepoint.com/sites/SiteName/Documenten/General/Test/Test.txt"

1
https:// or \\\\ may no be necessary.RanonKahn
@RanonKahn Tried my best but still can't seem to get it working. I edited my question so you can see the url my folder is in as well as the names of the folders. With that url, how would you try it out?Stan
The only issue could be sharepoint access. Try copying to some other folder on your computer or to another web folder.RanonKahn
The question has been answered here: stackoverflow.com/questions/61600652/…Esben Eickhardt

1 Answers

1
votes

I just tested the following code and it worked:

cmd <- paste("curl --max-time 7200 --connect-timeout 7200 --ntlm --user", "username:password",  "--upload-file Book1.xlsx","teamsites.companyname.com/sites/SandBox/Documents/UserDocumentation/Test/Book1.xlsx", sep = " ")
system(cmd)

I routinely use the following function.However, the only issue will be the file that was transferred will remain 'checked-out' until the File is manually 'checked-in' for others to use.

saveToSharePoint <- function(fileName) 
  {
   cmd <- paste("curl --max-time 7200 --connect-timeout 7200 --ntlm --user","username:password", 
              "--upload-file", paste0("/home/username/FolderNameWhereTheFileToTransferExists/",fileName), 
              paste0("teamsites.OrganizationName.com/sites/PageTitle/Documents/UserDocumentation/FolderNameWhereTheFileNeedsToBeCopied/",fileName), sep = " ")
   system(cmd)
  }

 saveToSharePoint("SomeFileName.Ext")